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

Progressive Lookup Function

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

    Progressive Lookup Function

    Hello,

    I put this in the newsletter this month (Oct 2005), but thought I'd post it here as well. This is a self contained progressive lookup function that is built for v6 and above. The function takes 4 arguments, the name of the lookup table, the name of an index based on the lookup table, the desired number of lines in the lookup control, and the desired width of the lookup control. So:

    vRecordNumberReturned = ProgressiveLkUp("customer","Lastname",20,40)

    Make sure your index key is in the format desired for the search string.

    This function should perform well on very large tables and/or over a network.

    Jim

    #2
    Jim

    An excellent function - Thank you

    A nice extra feature would be to pass an 'A' or 'D' for Ascending or Descending.

    I shall be using this function myself in an upcoming application where a lot of lookups will be required.

    Chris
    If It Works First Time, There's Something Wrong!!!

    Comment


      #3
      Jim is of course more qualified to answer your request but if you will permit an observation...


      If you want the choice of ascending or descending sort, you could create an index for each and pass the appropriate tag name to the function.
      There can be only one.

      Comment


        #4
        Hello Chris,

        Thanks for the kind words. I appreciate it.

        Stan is right on the money as always. This could be done 'on the fly' switching the 'same' instance of the Xdialog box back and forth.

        There are a couple things I would have liked to include in this routine:
        1) the ability to switch to various search criteria, on the fly. ie: change from a name search to an address search, etc

        2) I wanted to put the visual list box in a multi-column format for things like last, first name search. I think this would look a little nicer but would necessitate having 'parallel' arrays and or lists to handle the visual display versus the actual key value.

        But this is a freebie and I wanted to get it out this month as we didn't have a ton of content for the newsletter. Hopefully the Alpha community will pick this up, improve and share it back.

        Thanks again for the kind words. Let me know how it works for you. I'm especially interested to hear how it works with large tables and over less that stellar networks.

        Thanks,
        Jim

        Comment


          #5
          Re: Progressive Lookup Function

          Just a note to say thanks for a great function. I would say I am in the 'beginner/intermediate' class when it comes to xbasic and xdialog so modifying your code is a bit out of my depth without a little help. If you have time,
          could you give us a few pointers on how to set things up so that searches could be done on different fields ie: name, address etc.

          Comment


            #6
            Re: Progressive Lookup Function

            Copy and paste the function. Then, edit it by changing the field names, etc. to reflect the new search field.

            kenn
            TYVM :) kenn

            Knowing what you can achieve will not become reality until you imagine and explore.

            Comment


              #7
              Re: Progressive Lookup Function

              I looked at Jim's code and cannot identify where the field names are that need to be change. Everything seems to start with a v which I take to be a variable? Could you please identify in the code where the fields are that need to be changed. I'm sure that I'm not reading the code correctly!

              Thanks

              Alan

              Comment


                #8
                Re: Progressive Lookup Function

                Jim's code works by setting the primary index of the table here
                Code:
                t = table.open(vTableName,FILE_RO_SHARED)
                vIndex = t.index_primary_put(vIndexName)
                as the value in the type in field changes t.fetch_find(vTypeIn) is used to find the closest matching record using the index. then a list is built using the next number of records you have specified in the function parameter "vNumberOfLines AS N".

                So, if you want different values listed just change the index specified in the function parameter "vIndexName AS C"

                The values in the list are the values in the index not a particular field so construct an index that will display as you want. Like: alltim(Lastname) + ", " + alltrim(Firstname) would give you a list containg values in the form of

                Kiebert, Tim
                Lucas, Alan

                Don't forget that the function returns the record number.
                Tim Kiebert
                Eagle Creek Citrus
                A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                Comment


                  #9
                  Re: Progressive Lookup Function

                  Thank you Kenn, Alan and Tim for your suggestions.
                  I understand the concept of changing the arguments passed to the function 'hard coded' within a script so to speak. I was wondering if there was any way of changing them 'on the fly' ie:once the lookup was already open.
                  My appologies for not making my question more specific; your replies
                  have been very helpful, I'm going to rethink my approach to the problem.

                  Don

                  Comment


                    #10
                    Re: Progressive Lookup Function

                    Thank you Kenn, Alan and Tim for your suggestions.
                    I understand the concept of changing the arguments passed to the function 'hard coded' within a script so to speak. I was wondering if there was any way of changing them 'on the fly' ie:once the lookup was already open.
                    My apologies for not making my question more specific; your replies
                    have been very helpful, I'm going to rethink my approach to the problem.

                    Don

                    Comment


                      #11
                      Re: Progressive Lookup Function

                      Hello Don,

                      I was wondering if there was any way of changing them 'on the fly'
                      There are several ways to achieve this. For instance, if you put a row of buttons that corresponded to the different searches you'd like to accomplish, lets say: <Last Name> <Company Name> <State>
                      When the user presses a button, you'd change the value held in the vIndex variable to the desired index, blank out the 'search for' control, and re-build the list based on the new index.

                      Another way to accomplish this would be to use a modeless Xdialog display. One of the great things about Xdialog is that the construct of the display is simply a text string passed into the function ( ui_dlg_box() and ui_modeless_dlg_box() ). By using the same name for a modeless Xdialog display you can dynamically change the Xdialog on the fly.

                      This is a simple example but once you grasp this, then changing the field (index) for the progressive lookup is done by calling the same modeless xDialog box with different parameters.

                      Code:
                      vdlg = <<%dlg%
                      This is Text one;
                      The first display;
                      {line=1};
                      <Switch> <Close>
                      %dlg%
                      
                      vdlg2 = <<%dlg%
                      This is Text two;
                      The second display;
                      {line=1};
                      <Switch> <Close>
                      %dlg%
                      
                      vCode = <<%code%
                      if a_dlg_button = "Switch"
                      	a_dlg_button = ""
                      	if WhichVersion = "First"
                      		WhichVersion = "Second"
                      		ui_modeless_dlg_box("Test",vdlg2,vCode)
                      		else
                      		WhichVersion = "First"
                      		ui_modeless_dlg_box("Test",vdlg,vCode)
                      	end if
                      end if 
                      if a_dlg_button = "Close"
                      	ui_modeless_dlg_close("Test")
                      end if 
                      %code%
                      
                      dim WhichVersion as c
                      WhichVersion = "First"
                      
                      ui_modeless_dlg_box("Test",vdlg,vCode)
                      If you don't want to use the first two approaches you could also achieve the same effect by programically closing one modal Xdialog box and instantly open another 'identical' one with the different parameters. There would probably be a slight screen flicker as the next list was build, but it should be acceptable.

                      Good luck,
                      Jim

                      Comment


                        #12
                        Re: Progressive Lookup Function

                        Yes, the "v" usually indicates a variable. Open alphaSports and make note of the table and fields that contain the basic info such as the customer name, etc. Study the code and identify the variables; write down the names. compare the names of the fields and the 'Customer' table to the code.

                        Next, change the variable names, the table name and field names to reflect your table name, etc. If you don't want, a particular field, delete the code to which it refers. If you want to add a field, simply add the code by copying the part of the code dealing with the field and change the names.

                        I believe you will also need to create an index for each search field. I may have missed something but jump in and paly with it. That is the best way to learn.

                        kenn
                        TYVM :) kenn

                        Knowing what you can achieve will not become reality until you imagine and explore.

                        Comment


                          #13
                          Re: Progressive Lookup Function

                          Thanks Ken,

                          Good sound advice, I will play with it and conquer.

                          Alan

                          Comment


                            #14
                            Re: Progressive Lookup Function

                            I have put the 'new' progressive lookup into several apps and am beginning to find some anomolies.....

                            Mind you, these may be of my own doing and not a problem with the function.

                            Using the old 'Record List - List Box' method, the last name typed would remain at the top of the search box whenever a new record was initiated -- even if I had to leave the data entry form and create a new customer record so that I could enter the sales transaction (known hereafter as tx).

                            Maybe a little 'splanation' will help.
                            Entering sales txs, the new record button does a search for name using the function --- customer not in table.
                            Now the entire or partial name that was typed in for the search is still present in the entry area when I cancel the sales tx (ergo cancel the new record entry). Then press a button on the tx form to go to the 'new customer - modal form'. After completing new cus entry, return to tx form and press 'new record'.... the name is still in the entry area and the lookup has gone to the new customer record.....

                            with the new function, the entry area has been cleared... probably rightly so..

                            It's not a problem and the lookup works just fine -- just have to retype some data.

                            The other 'anomoly' is that after several entries, I seem to be losing the ability to use the up and down arrows to move the cursor.... Cursor movement was a really great improvement in the new function....

                            Noticed something in the AlphaSports Explained chm when looking at some of the functions for the 'property sheet'. Apparently Selwyn feels that a closing statement for the main function (when internal functions are present) has got to be specific to the main function..

                            At least that's what it looks like to me.... The function definition includes :
                            ( 1) and the main function close is : end function ( 1)------------------

                            My mind is not at Selwyn's level so I really have no idea what it means, it just looks like a close specific to the main function

                            My only concern is the loss of the cursor movement using the keyboard, but the world will continue with or without it.

                            D

                            Comment


                              #15
                              Re: Progressive Lookup Function

                              Had a problem with the build list in the progressive look up it was not displaying the last item in the list. Tom Cone finally solved the issue by commenting out part of BuildList section of the code. The full code function is included below.

                              Thank you Tom.

                              Alan


                              [CODE]
                              'Date Created: 22-Sep-2005 08:51:46 PM
                              'Last Updated: 02-Aug-2007 04:27:49 PM
                              'Created By : Jim Chapman
                              'Updated By : Tom
                              FUNCTION ProgressiveLkUp AS N (vTableName AS C, vIndexName AS C, vNumberOfLines AS N, vWidth AS N )

                              dim shared pos as n 'The position of the scroll bar
                              dim shared vList as c 'The list variable that is displayed in the control
                              dim shared vSelect as c 'The 'record' selected by the user
                              dim shared vTypeIn as c 'The variable that contains the 'search for' string the user types in

                              pos = 0
                              vSelect = ""
                              vTypeIn = ""
                              t = table.open(vTableName,FILE_RO_SHARED)
                              vIndex = t.index_primary_put(vIndexName)
                              t.fetch_first()
                              vFirstRecordNumber = t.recno()

                              vList = ""
                              vList = BuildList(t,vIndex,vNumberOfLines)
                              dim shared vpgdn as n

                              vDlg =vWidth],[varN->vNumberOfLines]vSelect^#vList!vList_*]{vscroll=%0,[varN->vNumberOfLines+1]%3,[varN->vNumberOfLines]pos!pos_Changed};

                              %dlg%

                              vDlg = replace_parameters(vDlg,local_variables())


                              vDlgReturn = ui_dlg_box("Look Up",vDlg, line_count(vList)
                              GetCurrentValues("PageDown",line_count(vList))
                              else
                              GetCurrentValues("PageDown",vNumberOfLines)
                              end if
                              case else
                              vList = BuildList(t,vIndex,vNumberOfLines)
                              GetCurrentValues("PageDown",1)
                              end select
                              end if

                              if a_dlg_button = "pgup"
                              a_dlg_button = ""
                              select
                              case pos > 1
                              GetCurrentValues("PageUp",1)
                              case else
                              for i = 1 to (vNumberOfLines + line_count(vList))
                              if t.bof(vIndexName)
                              exit for
                              end if
                              t.fetch_prev()
                              next
                              vList = BuildList(t,vIndex,vNumberOfLines)
                              GetCurrentValues("PageUp",1)
                              end select
                              end if

                              if a_dlg_button = "vList_Change"
                              a_dlg_button = ""
                              vCurrentLine = word_number_get(vList,vSelect,crlf())
                              vReturnString = GetCurrentValues("vList_Changed",vCurrentLine)
                              end if
                              if left(a_dlg_button,6) = "vList_"
                              a_dlg_button = ""
                              end if
                              %code%)
                              t.close()
                              vRecNumber = val(vSelect)
                              select
                              case vDlgReturn "OK"
                              ProgressiveLkUp = -1
                              case vRecNumber > 0
                              ProgressiveLkUp = vRecNumber
                              case else
                              ProgressiveLkUp = -1
                              end select

                              END FUNCTION


                              function GetCurrentValues as C (vWhatFired as c,vPositionNum as n)
                              vCurrentString = word(vList,vPositionNum,crlf())
                              '*****************************************************************************
                              '*** Uncommenting the following lines will cause the type in control to reflect
                              '*** highlighted selection when using page and arrow keys, mouse and scroll bar
                              '*****************************************************************************
                              'if vWhatFired "TypeInChanged"
                              ' vTypeIn = alltrim(substr(vCurrentString,at("}",vCurrentString)+1))
                              'end if
                              vTempLen = at("}",vCurrentString) - 7
                              vSelect = substr(vCurrentString,7,vTempLen)
                              pos = vPositionNum
                              GetCurrentValues = "T"
                              end function

                              function BuildList as c (vTable as p,vIndex as p,vCount as n)
                              BuildList = ""
                              ' for i = 1 to vCount
                              ' vKey = vIndex.key_get()
                              ' BuildList = BuildList + "{data="+padl(alltrim(str(vKey.record)),10,"0")+"}"+ vKey.key + crlf()
                              ' vTable.fetch_next()
                              ' if vTable.eof(vIndex.name_get())
                              ' exit for

                              Comment

                              Working...
                              X