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

Field to field comparison

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

    Field to field comparison

    Hi,

    I think I'm getting stupid as I get older...lol. What I am trying to accomplish is to compare one address field in tbl3 to an address field in tbl. If they match then a ui message box would say not to proceed. The coding seems simple to me except....it dosesn't work...lol. My code is as follows:

    dim tbl as P
    dim tbl3 as P
    dim user as C



    tbl3=table.open("ameregl3.dbf")

    user=ameregl3->address

    tbl=table.open("nonserve addresses.dbf")

    If user=nonserve_addresses->address THEN
    ui_msg_box("Attention","This is a NON SERVICE address. Do NOT Proceed",48)
    Else
    End

    tbl.fetch_find(address)

    While .NOT. tbl.fetch_EOF()
    tbl.Fetch_next()

    END WHILE

    END IF


    tbl=tbl.close()

    END

    Seems simple in theory but obviously I do not have enough experience in A5 yet. The above code works fine but unfortunately it doesn't seem to compare the fields in "tbl" to "tbl3" and display the message box if there is a matching address. I believe what it is doing now is checking the 1st field in "tbl" and then just fetching the other records in "tbl" without compaing them with the "address" field in tbl3. This is performed with a button on a form that is for tbl3, so in actuality (sic), tbl3 is already open.

    Open to suggestions... Thanks in advance for all the help.... this includes the past. This message board has to have the greatest people out there involved.

    Thanks again,

    Scott

    P.S. Probably won't be able to check the board again until Thursday Morning... Thx

    #2
    Re: Field to field comparison

    Scott,
    There are a few problems in your script and in the method.....and in your description of what exactly you are trying to do. :)

    First you are not even using the table pointers as you should be for the most part.
    Second, your loop through the table is after when you are trying to get values.

    The following will take the first record of tbl3 and compare it to each record in tbl unless a match is found--then the script ends after the message box. If speed is an issue (a lot of records), then a tbl.batch_begin() and tbl.batch_end() should be placed outside of the While...End While.

    This is most likely NOT exactly what you are trying to do though--see below for questions!
    Code:
    dim tbl as P
    dim tbl3 as P
    dim user as C
    
    tbl=table.open("nonserve addresses.dbf")
    tbl3=table.open("ameregl3.dbf")
    
    tbl.fetch_first()
    tbl3.fetch_first()
    While .NOT. tbl.fetch_EOF()
       user=tbl3.address
    
       If user=tbl.address
               ui_msg_box("Attention","This is a NON SERVICE address. Do NOT Proceed",48)
                   End
            tbl=tbl.close()
            tbl3.close()
       end if
    
       tbl.Fetch_next()
        
    END WHILE
        
    tbl=tbl.close()
    tbl3.close()
    END
    Now if you want to compare ALL the records in tbl3 to all the records in tbl then another loop is to be placed outside of the above for the tbl records.

    If instead you have a specific value you want to compare to all the records in tbl I need to know how this value is derived....if from a form then no reason to open the tbl3 table at all, but just check this value in the above loop....same thing for if the value comes from a variable.
    Last edited by MikeC; 04-13-2011, 12:18 AM.
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________



    Comment


      #3
      Re: Field to field comparison

      Scott,

      Your code does 1 compare, and if there is no match, it ends.

      Code:
      If user=nonserve_addresses->address THEN
      ui_msg_box("Attention","This is a NON SERVICE address. Do NOT Proceed",48)
      Else
      [COLOR="Red"]End[/COLOR]
      Mike's code will do the compare for all the records.

      This whole thing seems a little cryptic, though.

      If you do get a hit, you display a message and quit. Does that mean that if only one address matches, you want to quit?

      Again, I don't know all your logic, but if you are trying to make sure non-serviced addresses are bypasses in some other routine, like a report or query, you may want to "mark" those records as yo work through the tables, then use a ".not.marked()" as a filter on whatever other routine you are using to process the "good" records.

      Just my observations,

      Tom

      Comment


        #4
        Re: Field to field comparison

        Hi Guys,

        Thanks for the replies. Basically, what happens is this.... A person is checking just one address on one record in tbl3 and comparing it to all the records in tbl. However, in tbl, there will be less than 50 entries. So again, we are trying to compare just one address to all the addresses listed in tbl. If there is a match, then the dialoge box pops up and my employee will know to close out that particular record.

        Hope that makes a little more sense.

        Thanks again for all the help.

        Scott

        Comment


          #5
          Re: Field to field comparison

          So sorry, I forgot to answer your question MIke. The value is derived from a form linked to tbl3.

          Hope this helps.

          Thanks again,

          Scott

          Comment


            #6
            Re: Field to field comparison

            Why loop anything. It seems the user is in the form of tbl3. Why not get the address of this record and query tbl for the presence of this address in the tbl. Also, 50 records is nothing. If this needs to be done over and over, get 50 addresses into a variable with one opening of the table using table.external_record_content_get() one time and query that variable for the presence of the address. This is where I have learned to use filter_string_smatch(). Very powerful and very fast.

            Code:
            tbl3 as p
            dim vadd as C
            tbl3=table.get("ameregl3")
              vadd=tbl3.address
              if a5_get_records_in_query("nonserve addresses","address="+quote(vaddr))>0
                 ui_msg_box("Attention","This is a NON SERVICE address. Do NOT Proceed",48)
              end if
              End
            Last edited by Mike Wilson; 04-14-2011, 03:58 PM.
            Mike W
            __________________________
            "I rebel in at least small things to express to the world that I have not completely surrendered"

            Comment


              #7
              Re: Field to field comparison

              Hi Guys,

              I believe Mike's script will work if I take out the command to fetch each record in tbl3. However I do need to make sure that the focus is on the current record and address field of tbl3. The button to run this script is on the form where the address field appears in tbl3. I would think that it should put the focus on that particular record and field that is referenced. Not sure about that part though.

              Thanks for all the help!!

              Scott

              Comment


                #8
                Re: Field to field comparison

                I will give that a try Mike. It must be great to be so knowledgeable of A5 scripting. Slowly but surely I'm working on it...lol.

                Thanks again,

                Scott

                Comment


                  #9
                  Re: Field to field comparison

                  Hi Mike,

                  I tried your code but it did nothing unfortunately. I made sure to correct the first line and add "dim as". I'm still wondering if the focus is not on the current record in tbl3 that is currently open. Not sure.

                  As for looping, that was the only method that I am familiar with to accomplish this task.... I am still working at it though....lol.

                  Comment


                    #10
                    Re: Field to field comparison

                    If all you are doing is checking to see if a record exists, then I would use something along the following.

                    I am still not entirely certain of how you are getting the value of the address you wish to check.
                    if "The value is derived from a form linked to tbl3." means that you are on a record in a form that is to be checked, then you can get that record's ID value (your unique value that I am assuming you have created for each record--or have had Alpha do it...). I would take that value....or set a variable to that value first....and just use the Exist() function....but this means creating an index for the address field if it has not already been done.
                    http://support.alphasoftware.com/alphafivehelpv10/Functions/EXIST().htm
                    Code:
                    dim vaddress as c
                    vaddress=topparent:your_field_name.value
                    
                    If Exist(vaddress, "ameregl3", your_address_field_index)
                        msgbox("Field already exists!")
                      else
                        'do whatever here if anything when it doesn't exist
                    end if
                    I am not intentionally trying to confuse you, but just giving what I think is the best choice of many that can be used for your specific case.
                    Mike
                    __________________________________________
                    It is only when we forget all our learning that we begin to know.
                    It's not what you look at that matters, it's what you see.
                    Henry David Thoreau
                    __________________________________________



                    Comment


                      #11
                      Re: Field to field comparison

                      Thanks Mike I'll try that. Basically I AM looking to compare the value in one field to the value in another field in another table. If the value exists in both tables, then the script ends and my employeeenters some info and closes the current record they are working in which is where the first value is derived.

                      Not sure if that's clear but in a nut shell, that's what I am trying to accomplish.

                      Many Thanks!!!

                      Scott

                      Comment


                        #12
                        Re: Field to field comparison

                        Hi Mike,

                        I tried your code and still nothing. Here is the code:

                        dim vaddress as c

                        vaddress=topparent:address.value

                        If Exist(vaddress, "nonserve addresses", "address")
                        ui_msg_box("ATTENTION!""Field already exists!",48)
                        else
                        END
                        end if

                        END

                        I assume this will check the value in the "address" field in amegl3.dbf (which is what the topparent form is attached to), and then compare that value to all the entries in the "address field" of nonserve addresses.dbf. If this theory is correct, when I run the script (from a button on the currently opened form), nothing happens. I have the address in the current form also entered into the nonserve addresses table. Theoretically, it should see that and the message box should pop up.

                        Not sure where I'm still going wrong. I won't be back in my office until Monday morning. Thanks for all your help and direction Mike. Maybe you can create 2 tables and a form and try it yourself. Anyway...

                        Many Thanks,

                        Scott

                        Comment


                          #13
                          Re: Field to field comparison

                          EDITED!!!

                          add a comma to the ui_msg_box(). The second argument is the table name---You should not have any spaces in table/field/index names as dictated by Alpha's naming convention. I am assuming that the 3rd argument is your index "address". When entering code into the code editor, right click between the arguments and many times a drop down will appear for choices--the index argument has this feature.
                          Code:
                          If Exist(vaddress, "nonserve addresses", "address")
                              ui_msg_box("ATTENTION!"[SIZE=6][COLOR=Red],[/COLOR][/SIZE]"Field already exists!",48)
                            else
                              END
                          end if
                          Eliminate the last END
                          Last edited by MikeC; 04-14-2011, 08:19 PM.
                          Mike
                          __________________________________________
                          It is only when we forget all our learning that we begin to know.
                          It's not what you look at that matters, it's what you see.
                          Henry David Thoreau
                          __________________________________________



                          Comment


                            #14
                            Re: Field to field comparison

                            Mike,
                            I love you bro, but let's get on board so we don't spin this guy into a tizzy. Why complicate things with a damn index. Screw the index, it only makes things unneedingly complicated. There are only 50 records in the nonserve addresses lookup table. An index is unnecessary. The code I gave is the simplest without need to manage an index. I just didn't DIM the pointer. It should work just fine.

                            Code:
                            [COLOR="Red"]DIM[/COLOR] tbl3 as p
                            dim vadd as C
                            tbl3=table.get("ameregl3")     ' current record in focus on the form
                              vadd=tbl3.address
                              if a5_get_records_in_query("nonserve addresses","address="+quote(vaddr))>0
                                 ui_msg_box("Attention","This is a NON SERVICE address. Do NOT Proceed",48)
                              end if
                              End
                            Mike W
                            __________________________
                            "I rebel in at least small things to express to the world that I have not completely surrendered"

                            Comment


                              #15
                              Re: Field to field comparison

                              so we don't spin this guy into a tizzy
                              My worry exactly....just so many ways to do as Scott wants....and we don't know how familiar he is with programming in general.


                              Why complicate things with a damn index. Screw the index, it only makes things unneedingly complicated
                              :D :D

                              I believe that indices only appear complicated when you don't know or understand what they do or how to create one.
                              But have to say that learning about indices early on would have helped me considerably as it opens up many more functions that require an index. Even just knowing in a very general way that all an index really is, is a way to order the records of a field(s) in a table--analogous to the index in a book....and that ordering the records in this way for a specific field you are "querying", will speed up the process sometimes significantly. As so many functions require an index, I really do think it is prudent, even for xbasic newbies, to learn about them.

                              So to create an index, you right click on a table----choose Define Indexes----create a name (10 characters or under generally), choose the relevant field, the order (ascending usually), and type (usually All). Usually no filter at all except for very specific situations (have read that filtered indices can corrupt more easily--not proven IMO).

                              There!! Definitely enough said!! :)

                              Scott, just choose any of the methods/choices given and we should be able help get it going for you--but for sure try to understand exactly what is being given.
                              Last edited by MikeC; 04-15-2011, 03:14 AM.
                              Mike
                              __________________________________________
                              It is only when we forget all our learning that we begin to know.
                              It's not what you look at that matters, it's what you see.
                              Henry David Thoreau
                              __________________________________________



                              Comment

                              Working...
                              X