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

Iterate Index Keys ?

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

  • MoGrace
    replied
    Re: Iterate Index Keys ?

    When it takes me more than an hour to find something in here due to broken links, I feel I should share my discoveries...

    I have a form with an embedded browse that is difficult to see when the last record in the browse has been reached when the user moves thru the records using a navigation button. So I wanted to add a sound to notify the user he was on the last record so he knows to move to the next parent record.

    Here are the 2 methods I found useful:

    lrec = browse1.Index_pointer().Find_Last().record

    ?typeof(lrec)
    = "N"

    ?lrec
    = 50

    cur_rec = browse1.Table_Get().recno()

    ?cur_rec
    = 13

    So I set these up as shared variables, setting the 1st in the OnFetch event of the form, and the 2nd in the OnRowChange event in the browse - where I test if they match and if so, do a ui_beep().

    Now when the user fetches a new parent record the first function gets the new last record number for the browse. Then regardless of how the browse is navigated (using a button or not), when the last record in the browse is reached the two variables will match and the system will now beep!

    btw searching the Wiki for 'find_last' does produce a couple of links for index or query - but the scripts are more complex than this was - Which I found searching the browse1 methods for the form in the IW.
    Last edited by MoGrace; 01-07-2018, 05:20 PM.

    Leave a comment:


  • Tim Kiebert
    replied
    Re: Iterate Index Keys ?

    Originally posted by Tom Cone Jr View Post
    Tim, I am not trying to eliminate network traffic, just minimize it, cause I am trying to populate a listview control as fast as possible. I'm thinking that if the index key is all that needs to be stuffed into the control, then it's faster to pull it directly from the index, than from the table, especially in cases where the record structure in the table is pretty big and the record count is high.

    -- tom
    I kind of thought as much but figured I would throw the idea into the mix.

    Cheers

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Iterate Index Keys ?

    Thanks, guys. It turns out I was using the find_next() method incorrectly. I was passing an index pointer to the method, instead of a pointer to the key. I appreciate the help. This will get me where I need to go (barring other excursions into the land of badly written code!).

    Tim, I am not trying to eliminate network traffic, just minimize it, cause I am trying to populate a listview control as fast as possible. I'm thinking that if the index key is all that needs to be stuffed into the control, then it's faster to pull it directly from the index, than from the table, especially in cases where the record structure in the table is pretty big and the record count is high.

    -- tom

    Leave a comment:


  • Tim Kiebert
    replied
    Re: Iterate Index Keys ?

    In light of Martin's comments, I think even my previous post won't eliminate network traffic as I think each read of the index would still mean a trip to the server. Albeit with a lot less data to transmit. You could bring all the keys over in one trip using the <INDEX>.KEY_LIST_GET() method. With something like the following which would result in a variable holding all the keys. Then you would need to use character functions to do teh remainder of the processing. Maybe even populate an array.
    Code:
    dim tbl as P
    dim indx as P
    dim keylist as C
    tbl = table.open("customer")
    
    indx = tbl.index_primary_put("Lastname1")
    keyList = indx.key_list_get(indx.records_get(),1,"K"+crlf())
    msgbox(keylist)
    
    tbl.close()

    Leave a comment:


  • Tim Kiebert
    replied
    Re: Iterate Index Keys ?

    Tom, the following code runs in Alphasports. It should show that the index gets looped through without moving the record pointer of the table.

    Code:
    dim tbl as P
    tbl = table.open("customer")
    
    indx = tbl.index_primary_put("Lastname1")
    
    lst = indx.find_last()
    b= indx.find("Smith")
    
    msgbox("Find 'Smith' in Index, Table pointer not moved",b.key  + b.record + crlf(2)+ tbl.Lastname +tbl.recno())
    
    tbl.fetch_first()
    
    msgbox("Find 'Smith' in Index, Table pointer moved to first record","In this case the first record is according to the index used." + crlf(2) +\
            b.key  + b.record + crlf(2)+ tbl.Lastname +tbl.recno())
    For i = 1 to 10
        if b.record =lst.record then
            exit for
        end if
        b=indx.find_next(b)
        msgbox("Find next key in Index, Table pointer stays on the first record","Loop number " + i+crlf(2)+ \
                b.key  + b.record + crlf(2)+ tbl.Lastname +tbl.recno())
    Next
    
    tbl.close()
    I see Steve beat me to it. Must have been those extra message boxes I threw in there. :)
    Last edited by Tim Kiebert; 07-13-2009, 11:57 AM.

    Leave a comment:


  • Steve Andrews
    replied
    Re: Iterate Index Keys ?

    Originally posted by Tom Cone Jr View Post
    I'm finding that <index>.find_next() always returns a pointer to the index key that's "next" in relation to the tables record pointer. Can't use it to step through the keys in the index (without also stepping through the records in the table).-- tom
    Tom,

    I'm failing to see why the find_next() cannot be used. I ran the code below and it went through every key of the index "Dept" without loading table records.

    Code:
    dim pFirst as P
    dim pLast as P
    dim pKey as P
    
    tbl = table.open("codes")
    ndx = tbl.index_primary_put("Depts")
    
    pLast = ndx.find_last()
    pFirst = ndx.find_first()
    
    pKey = ndx.key_get()
    ui_msg_box("Started",str(pKey.Record))
    
    while pKey.Record <> pLast.Record
    	pKey = ndx.find_next(pKey)
    	ui_msg_box("Next",str(pKey.Record))
    wend	
    
    tbl.close()
    Am I misunderstood in what you are trying to achieve?

    Steve

    Leave a comment:


  • martinwcole
    replied
    Re: Iterate Index Keys ?

    Tom, it sounds almost like you want to open the "cdx" file for a table and read the entries that way. Short of getting someone like Selwyn to write a script with commands that they have available we don't have or don't know about, you might want to consider a query - since the query is saved locally, containing the keys, and you could thus fetch through the query without network traffic. The data has to either be local or in a memory buffer - how else could you do it?

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Iterate Index Keys ?

    Thanks for the link to the release notes. I'm not sure this new table method will avoid the network traffic that will otherwise occur if one steps through all the records in a large table using the cursor. Hard to imagine that it might.

    -- tom

    Leave a comment:


  • milesjg
    replied
    Re: Iterate Index Keys ?

    Sorry about that;

    I did mean <tb>.get_cursor(). Was just going by memory, should have check first.

    Leave a comment:


  • Tim Kiebert
    replied
    Re: Iterate Index Keys ?

    I think James meant <tbl>.get_cursor()

    This is another item that has not yet made it into the regular help file.

    Its usage is outlined in the release notes for the patches.
    Build 1471-3180 9-May-2008

    Leave a comment:


  • Tbaker
    replied
    Re: Iterate Index Keys ?

    Tom

    Look here


    http://support.alphasoftware.com/alp...RSOR_GET().htm

    Tom B.

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Iterate Index Keys ?

    James, no, haven't considered that.

    a) I don't understand the cursor_get() method and can't find it's documentation; and

    b) I am trying not to fetch records from the table as I step through the index.

    My goal is to be able to jump to an index key in a specific index, and then build a list of the next 100 index keys from there as fast as possible. I'd like to avoid clogging the network with fetches to the table itself.

    Leave a comment:


  • milesjg
    replied
    Re: Iterate Index Keys ?

    Tom;

    Did you try some "sort" of application of <tbl>.cursor_get()
    Since when you move the pointer in a cursor you do not change the record that the base table (open) pointer is pointing to. ?

    Leave a comment:


  • Tom Cone Jr
    replied
    Re: Iterate Index Keys ?

    Thanks, Martin.

    I'm not trying to enumerate the index tag specifications.

    I'm trying to "fetch" through the keys for a specific index without fetching records in the related table. i.e find_first(), then find_next() over and and over until there are no more keys in the specific index list.

    Leave a comment:


  • martinwcole
    replied
    Re: Iterate Index Keys ?

    Tom, as for actual indexes for the table (not temporary ones) you could use the script Selwyn gave us to save the indexes for all tables to a text file - I save the indexes to a table instead of a text file, with the tablename as the first field, and the indexes in a memo - so I can fetch a specific table and get the indexes from the memo - although a bit of a kludge, it will work

    Leave a comment:

Working...
X