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

How To Run LOOKUP a Single Time, Produce Multiple Resulting Variables, Each With A Different Value From The Record

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

    How To Run LOOKUP a Single Time, Produce Multiple Resulting Variables, Each With A Different Value From The Record

    I'm just understanding how to use LOOKUPC() and LOOKUPN(), from what I've seen, that function allows you to quickly locate a target record and return a single value of a single record, and, store that value in a variable.
    Suppose I want to retrieve multiple values from that single record and store each one in its own variable, The only way I can think of right now is to run the LOOKUP() multiples times and retrieve each desired value on each run.
    Is there a way to run the LOOKUP() just once and retrieve multiple values from the record?
    Example, suppose I run LOOKUPC() on a "Products" table, and, from the record that it locates, I want to store a variable for each of the following:
    Product_ID
    Dept_ID
    Item_Num
    Descrip
    Price

    I feel this is where an array comes in, but, I haven't found any viable solution so far. I'm not experienced with Arrays.

    #2
    The documentation suggests that it is possible to return multiple fields from a LookupC, Nigel.
    Sounds like it would be possible to assign the values from a multi field returned lookup.
    See our Hybrid Option here;
    https://hybridapps.example-software.com/


    Apologies to anyone I haven't managed to upset yet.
    You are held in a queue and I will get to you soon.

    Comment


      #3
      Set lookupc() to return a string containing each field value, separated with a convenient delimiter character. i.e. define an expression to concatenate the desired field values, separated with the delimiter. I often use "*". Then parse the string into its parts with separate calls to the word() function.

      Comment


        #4
        Or write your own function and return a pointer variable with all of the variables needed.
        Al Buchholz
        Bookwood Systems, LTD
        Weekly QReportBuilder Webinars Thursday 1 pm CST

        Occam's Razor - KISS
        Normalize till it hurts - De-normalize till it works.
        Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
        When we triage a problem it is much easier to read sample systems than to read a mind.
        "Make it as simple as possible, but not simpler."
        Albert Einstein

        http://www.iadn.com/images/media/iadn_member.png

        Comment


          #5
          An example of multiple field lookup:
          multi = lookupc("F",inv.course_id,"dtoc(COURSE_DATE)+TCHR_ID+tfc_id+tfc_name","courses","Id") 'multiple fields
          eval("tbl.K"+str(x,1,0)+"datum") = ctod(left(var->multi,10))
          eval("tbl.K"+str(x,1,0)+"nr") = inv.course_id
          tbl.Dozent = mid(var->multi,11,5)
          tbl.Schulid = mid(var->multi,16,5)
          tbl.Schulort = mid(var->multi,21,38)
          Jo Hulsen
          Dommel Valley Solutions
          The Netherlands

          Comment


            #6
            I don't know what context you are doing this.

            Have you considered having a set that includes the table that you are looking up to?
            Al Buchholz
            Bookwood Systems, LTD
            Weekly QReportBuilder Webinars Thursday 1 pm CST

            Occam's Razor - KISS
            Normalize till it hurts - De-normalize till it works.
            Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
            When we triage a problem it is much easier to read sample systems than to read a mind.
            "Make it as simple as possible, but not simpler."
            Albert Einstein

            http://www.iadn.com/images/media/iadn_member.png

            Comment


              #7
              Sorry, I should have tested my code first. This works now in the interactive window.

              From the help

              Dim My_Return_Var as A
              Lookup_Value as A = LOOKUP( Lookup_Table as C, Filter as C, Lookup_Expression as C )

              Code:
              Dim My_Return_Var as A
              My_Return_Var = lookup("products","Product_ID = '12345' " , "Product_ID + '*' + Dept_ID + '*' + Item_Num + '*' + Decript + '*' + Price")
              
              varProduct_ID = word(My_Return_Var,1,"*")
              varDept_ID = word(My_Return_Var,2,"*")
              varItem_Num = word(My_Return_Var,3,"*")
              varDescrip = word(My_Return_Var,4,"*")
              varPrice = word(My_Return_Var,5,"*")
              
              ?varProduct_id
              = "12345"
              
              ?varDept_ID
              = "55555 "
              
              ?varItem_Num
              = "55555-01 "
              
              ?varDescrip
              = "Widget "
              
              ?varPrice
              = "15.59"
              Note: I used lookup() as you are returning both characters and numbers

              Last edited by Ronald Anusiewicz; 08-10-2020, 12:11 PM.
              Alpha 5 Version 11
              AA Build 2999, Build 4269, Current Build
              DBF's and MySql
              Desktop, Web on the Desktop and WEB

              Ron Anusiewicz

              Comment


                #8
                Thanks very much guys. I got it working after the 1st 2 posts from Ted and Tom, then, Ronald kinda confirm I was on the right path with is example.
                The following is what I did and it works.

                Dim TN as C
                Dim Found_Product As C

                TN = table.filename_get("products")

                Found_Product = Found_Product = lookupc("F",Product_Lookup,"Product_ID + "*" + Item_Num + "*" + Dept_Id + "*" + Department + "*" + Tax + "*" + str(Un_Price,19,11) + "*" + str(T_Price,19,11) + "*" + str(Qty_Onhand,19,3)",TN,"Alu")

                DIM GLOBAL Invoice_Nu AS c
                Invoice_Nu = :POS:invoice_nu.value

                tbl = table.open("invoice_items")
                tbl.enter_begin(.T.)
                tbl.Invoice_Nu = INVOICE_NU
                tbl.Product_id = word(Found_Product, 1, "*")
                tbl.Item_num = word(Found_Product, 2, "*")
                tbl.Dept_Id = word(Found_Product, 3, "*")
                tbl.Department = word(Found_Product, 4, "*")
                tbl.Price = Val(word(Found_Product, 6, "*"))
                tbl.T_Price = Val(word(Found_Product, 7, "*"))
                tbl.Qty_Before = Val(word(Found_Product, 8, "*"))

                tbl.enter_end(.T.)
                tbl.close()

                As you can see, this function eliminated the need to place the data from each field into individual variables, I was able to fetch each fields data straight from the main variable into target table.

                After looking at Ronald's example and his explanation as to why he used LOOKUP() as opposed to LOOKUPC() (which makes sens as I am retrieving both character and number), I'm left wondering, if LOOKUP() is good for whatever data type I'm retrieving, what's the purpose/benefit/need for LOOKUPC() and LOOKUPN(), why do those even exist ??? Please note, that in my codes above, I used LOOKUPC(), I then converted the numeric data into character so they would be compatible. Ronald used LOOKUP() and didn't need to convert his data. This is a POS system and speed in very important, is there any speed difference between these 2 functions?

                Comment


                  #9
                  With lookup you can search any field in the table, with lookupC etc. you must search an indexed field for the match. I assume this is much quicker

                  Comment


                    #10
                    Looks like this could be a field rule table lookup and would be easier and better performance.
                    Al Buchholz
                    Bookwood Systems, LTD
                    Weekly QReportBuilder Webinars Thursday 1 pm CST

                    Occam's Razor - KISS
                    Normalize till it hurts - De-normalize till it works.
                    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                    When we triage a problem it is much easier to read sample systems than to read a mind.
                    "Make it as simple as possible, but not simpler."
                    Albert Einstein

                    http://www.iadn.com/images/media/iadn_member.png

                    Comment


                      #11
                      I switched my LOOKUPC() to LOOKUP(), I'm not sure which one armasoft was referring to when he said "I assume this is much quicker". So far the result seems very promising, but it hasn't been tested in the field as yet.

                      Dim Found_Product As C
                      DIM filterstring as c
                      filterstring = "UPC = " + s_quote(Product_Lookup)
                      Found_Product = lookup("products",filterstring,"Product_ID + "*" + Item_Num + "*" + Dept_Id + "*" + Department + "*" + Tax + "*" + Un_Price + "*" + T_Price + "*" + Qty_Onhand")

                      DIM GLOBAL Invoice_Nu AS c
                      Invoice_Nu = :POS:invoice_nu.value

                      tbl = table.open("invoice_items")
                      tbl.enter_begin(.T.)
                      tbl.Invoice_Nu = INVOICE_NU
                      tbl.Product_id = word(Found_Product, 1, "*")
                      tbl.Item_num = word(Found_Product, 2, "*")
                      tbl.Dept_Id = word(Found_Product, 3, "*")
                      tbl.Department = word(Found_Product, 4, "*")
                      tbl.Price = Val(word(Found_Product, 6, "*"))
                      tbl.T_Price = Val(word(Found_Product, 7, "*"))
                      tbl.Qty_Before = Val(word(Found_Product, 8, "*"))

                      tbl.enter_end(.T.)
                      tbl.close()

                      For now I'm very hopeful. Thanks to everyone for their time and assistance.

                      Comment


                        #12
                        I'd expect the standard lookup() to be slower as it isn't necessarily using indexed records

                        Comment


                          #13
                          Currently, I am using lookup() on fields that do have index.
                          Some of the fields in the results are not indexed, like "price" for example, but the fields that are searched are all indexed.

                          Comment


                            #14
                            If it works, Nigel, stop fiddling.
                            See our Hybrid Option here;
                            https://hybridapps.example-software.com/


                            Apologies to anyone I haven't managed to upset yet.
                            You are held in a queue and I will get to you soon.

                            Comment


                              #15
                              Lol! I will Ted.
                              It wasn't working fast enough before, but it seems to be on the right path now.

                              I really appreciate everyone's contribution.

                              Comment

                              Working...
                              X