Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

KEY_EXIST

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    KEY_EXIST

    Hi,
    I am having some difficulty in trying to prevent the entry of duplicate records in a database table. I have created a field called "Unique" which contains
    Trim(Lastname)+substr(inits,1,1)+pcode - Post Code is the UK equivalent
    of US Zipcode.
    I have indexed the table on this field.
    Within a script on my 'save' button I have tried the following:
    tbl = table.current()
    indx=tbl.index_primary_put("unique")
    if key_exist("tv->unique",trim(tv->name)+substr(tv->inits,1,1)+alltrim(tv->pcode))
    dim reply as n
    then reply= ui_msg_box("POSSIBLE DUPLICATION", "This Name,Initial and Post Code already exist. Proceed",36)
    if reply= 6 then
    end if
    elseif reply=7
    goto end5
    end if
    oktosave = .t.
    end5:
    ui_msg_box("DUPLICATION OF RECORD", "Save this entry and check the Database",0)
    goto start

    It does not work - the message says that the index does not exist. What am I doing wrong?

    Rev'd Peter Lear

    #2
    RE: KEY_EXIST

    Peter:

    this I queston this line...

    if key_exist("tv->unique",trim(tv->name)+substr(tv->inits,1,1)+alltrim(tv->pcode))

    I don't think the index tag name needs the 'tv->' prefix and should just simply be "unique" The script finds it to 'primary_put' it but cant find it with that prefix.

    Give it a shot!

    Ken

    Comment


      #3
      RE: KEY_EXIST

      Peter,

      My first check would be
      1.You wrote
      if key_exist("tv->unique",trim(tv->name)+substr(tv->inits,1,1)+alltrim(tv->pcode))

      Strip out the tv->
      if key_exist("unique",trim(tv->name)+substr(tv->inits,1,1)+alltrim(tv->pcode))
      2.
      Why are you using tv-> for the fields if they belong to table.current()

      Michael

      Comment


        #4
        RE: KEY_EXIST

        Rev'd Peter Lear

        your examples are:
        Trim(Lastname)+substr(inits,1,1)+pcode - Post Code is the UK equivalent
        of US Zipcode.
        I have indexed the table on this field.
        Within a script on my 'save' button I have tried the following:
        tbl = table.current()
        indx=tbl.index_primary_put("unique")
        if key_exist("tv->unique",trim(tv->name)+substr(tv->inits,1,1)+alltrim(tv->pcode))
        ----
        your index uses the full pcode field. when you test for its existence you trim the pcode field. this could be the problem.

        bob adler

        Comment


          #5
          RE: KEY_EXIST

          Missed that Bob

          Comment


            #6
            RE: KEY_EXIST

            Look in the 4.03 readme for a discussion of the key_unique function which is what you should be using. The document makes an explicit comparison of key_exist and key_unique. If you use the former you will encounter problems whenever you need to change a record.

            Bill
            Bill Hanigsberg

            Comment


              #7
              RE: KEY_EXIST

              Most grateful for all comments. Will roll up sleeves and let you know in due course. Thanks Peter Lear

              Comment


                #8
                RE: KEY_EXIST

                Thanks for the replies.

                I have now had a few minutes to play with the script. I cannot get it to run. The table is 'tv' and there is a field called 'unique' which is calculated as Upper(trim(name)+substr(inits,1,1)+alltrim(pcode)) - and I have looked on the browse and that gives the desired result. i have then indexed this field and called the index 'unique'. (I did all this before I knew of KEY_UNIQUE)

                When i tried running:
                if KEY_UNIQUE("unique") then - etc the message was - 'not an open index'. So I tried using index_get and that didn't work. This is what I find so infuriating about Xbasic. Nowhere can I find an explanation of the syntax that an ordinarily intelligent mortal can grasp.

                In pseudo code, all I want to achieve is:

                Does the combinatiojn of Name, first initial and postcode exist in the database - then show a message that this may be a duplicate record - BUT I still need to be able to save it - I may well have a Mrs V Smith living 2 doors apart - it has happened.

                Help - your frustrated brother

                Peter Lear

                Comment


                  #9
                  RE: KEY_EXIST

                  Peter,

                  Just a Question. Pardon my ignorance. If you are entering the record, does the field yet exist BEFORE saving? If not, on depart from each field, save A_FIELD_VALUE to a variable, then build your "unique" key from the variables.
                  Use the variables to check against the key. My understanding is that the fields in the tv table don't really exist until they are saved. If I am wrong, please disregard my post.

                  Tom Henkel

                  Comment


                    #10
                    RE: KEY_EXIST

                    Tom
                    Thank you, I take your point. in fact I am including the a_field_value in the expression. However, I am having difficulty getting the a_field_value to work.

                    Peter

                    Comment


                      #11
                      RE: KEY_EXIST

                      hi, peter,

                      I am not sure it is necessary, but are you using capital letters for A_FIELD_VALUE? I remember we had some problems with A_FIELD_VALUE giving us the next or previous field, you may want to try the "can depart" event. I also, for debugging purposes, put a "ui_msg_box" with the value of the variable I assigned from A_FIELD_VALUE on each depart to see what was happening.

                      Hope some of this helps.


                      Tom

                      Comment


                        #12
                        RE: KEY_EXIST

                        Tom
                        I wasn't - I will try. The ui msg box is a good idea, as is the on_depart tip. Thanks - I'll give that a whirl.

                        Peter Pear

                        Comment


                          #13
                          RE: KEY_EXIST

                          Peter, remember that the error messages are not always correct. Some errors don't seem to know what message to send so they just seem to pick the best they can find - which is usually misleading. I think in this case your problem may be that you are trying to 'change' the index while you are still in the "ENTER" mode and the system doesn't like that but isn't giving a clear error message.

                          Try changing the TBL = TBL.CURRENT() to TBL = TBL.OPEN( "" ).
                          This will open another copy of the table so that you can set the index and perform your search.

                          Remember to close the table when you're done.

                          Cal

                          Comment


                            #14
                            RE: KEY_EXIST

                            Cal

                            Thanks

                            Tom Cone is having a look at the dog's breakfast I am making. I will make the final solution known when he has had a moment to look.

                            Peter Lear

                            Comment


                              #15
                              RE: KEY_EXIST

                              For those of you who have been following this thread, we worked out a solution using the exist() function in a script that is run when the user pushes the
                              Save Changes button.

                              The script validates key fields needed in each record;
                              Then builds a search key by concatenating values from three fields;
                              Then uses exist() to see if an entry matching the search key is already present in an index.

                              Two tricks:
                              1) the index definition must match the search key concatenation sequence exactly; and
                              2) the search must be done after changes to the record start, but before they're written to the table.

                              Efforts to use key_unique() in the Save Changes script failed. It seems to have been designed to be used when the focus is on a field in the form, and works great in a field rule. However, when focus shifts away from the 'current' field to a button on the same form, it can't be used to check whether the 'current' value matches an entry in an index list. I have supposed that this is because there is no 'current' value, once focus leaves the field. Makes sense in a way, doesn't it?

                              -- tom

                              Comment

                              Working...
                              X