Alpha Video Training
Results 1 to 3 of 3

Thread: Re-ranking recs in a browse

  1. #1
    Member
    Real Name
    Trevor Sayers
    Join Date
    Jan 2004
    Posts
    118

    Default Re-ranking recs in a browse

    Hi folks,

    this is one of those that looks like it should be dead easy but it's not turning out that way.


    What I am trying to do:
    I have a single table with an embedded browse ordered ascending by a field called 'rank'. All I am trying to do is to insert a new rec ranked immediately below the active rec with the only change to *everything* I can see being that all recs below the active rec, move down one position and the new rec is inserted. That's it.

    The table is enclosed for your perusal. The embedded form is the one in question and the 'insert' button has the latest version of the script attached. Clearly performance should be as fast as possible.

    Just to be absolutely clear...
    Say before we press the 'insert' button, of 90 recs in the table, 20 are 'found' as they have a rank value, and of those 20, the browse is scrolled down a little so it is actually showing recs ranked 6 to 18 with rec 11 as the active rec. When the button is pressed, all recs in the entire table with rank"12 should have their rank value increased by 1 and when we're done, 21 recs should be 'found' and the browse should still be showing recs ranked 6 to 18, though clearly the new rec will be at 12, the rec that was 12 is now 13, 13 is 14, 14 is 15 etc and the rec that was 18 is now 19 and so it's off the bottom of the browse now and doesn't show unless we scroll down.


    The problems:
    The OnPush for 'insert (array)' does nearly everything I want but performance is unacceptably poor even with just 20 or so recs (it dumps rec nums to an array and then calls each rec in turn). An update operation is much quicker but I'm going round in circles trying to get it to work. I have tried Action Scripting it - 'Insert (AScr)' but while I can get an update to run fine if I manually enter the starting rec's rank using an ask() variable, I can't get it to pick up the rank value from the current rec without problems and I constantly get errors of "Error: Can't update field in primary index" even if I set the primary index to some field other than 'rank'.


    Thanks in advance for any help.

    Regards, as ever,
    Trevor


    PS Does anyone have an example of how to use flag variables?

    PPS Do I have to use an embedded rather than named browse here to be able? If I use a named browse, how do I detect the rank of the current active rec?

  2. #2
    Member
    Real Name
    Trevor Sayers
    Join Date
    Jan 2004
    Posts
    118

    Default RE: Re-ranking recs in a browse

    Oops, that should be...
    " all recs... with rank"11 should have their rank value increased by 1"

  3. #3
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,629

    Default RE: Re-ranking recs in a browse

    Trevor,

    You might want to do this update "upside down". That is, find the highest value (which I think you can do with the Max() or tablemax()function and add 1 from the top down. That way, you don't end up with duplicate numbers.

    Something like:

    dim biggest_no as N
    dim current_no as N
    tbl=table.open_current()
    tbl.index_primary_put("rank")
    current_no=tbl.rank
    biggest_no=tablemax("rank")
    for i=biggest_no to current_no step-1
    tbl.fetch.find(i)
    tbl.change_begin()
    tbl.rank=table.rank+1
    tbl.change_end(.t.)
    next i

    tbl.enter_begin()
    tbl.rank=current_no
    tbl.enter_end()

    then resynch your browse.

    Pat

Similar Threads

  1. Number of child recs belonging to parent
    By Jim Chapman in forum Archived Wishlist
    Replies: 5
    Last Post: 07-26-2005, 07:11 AM
  2. Update - uses all recs not selected
    By dik_coleman in forum Alpha Five Version 6
    Replies: 2
    Last Post: 03-13-2005, 08:40 AM
  3. Can't get browse edited browse table to work
    By hanson in forum Alpha Five Version 6
    Replies: 8
    Last Post: 08-07-2004, 11:17 AM
  4. Ranking numbers
    By Glenn Chandler in forum Alpha Five Version 4
    Replies: 5
    Last Post: 12-27-2002, 05:48 AM
  5. Update child recs bases on parent filter
    By Michael Humby in forum Code Archive
    Replies: 1
    Last Post: 05-05-2002, 02:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •