×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Change Record Position by Buttonclick
2

Change Record Position by Buttonclick

Change Record Position by Buttonclick

(OP)
Hello, this is my first post to this forum. Hopefully someone here can help me.

Here's my problem: I have a browse-window showing several records. Each record has tweo fields: one for the name, the second for it's position within the queue.

BMW       1
PORSCHE   2
FIAT      3
DODGE     4

Also on the form are two buttons, one labeled UP, the other labeled DOWN. Let's say I click the record FIAT, positioned on 3 - then I click the UP Button. This is what i want:

BMW       1
FIAT      2
PORSCHE   3
DODGE     4

Had I pressed down, FIAT would now be on pos. 4 and DODGE would be on position 3. As you may notice, this sort of function is quite common in many applications. Being a total newbie to Clarion I would really appreciate some help! Please consider my very limited knowledge when answering ;) !!

Thanx!

RE: Change Record Position by Buttonclick

(OP)
...waiting for an answer I've tred to manage the task by using the POSITION() command - and I just can't get it to work. The problem seems so simple. I Have also tried to solve it via CHOICE(). Works fine as long a the queue list is not longer than the browse window, thus forcing a scroll. The visable position is returned, sadly not the position within the queue...

(..Help!!!)

RE: Change Record Position by Buttonclick

Check www.vividhelp.com. They have some free stuff which includes SHUFFLER template which allows you to move the postion of records in a browse up & down. This will help you achieve it without coding.

If you want to code it yourself, here is the code to execute on Accepted of the UP button :

Assuming ?List is the List Box and BrowseQ is the Queue of the Browse and Pos is the Position field and is numeric,

R# = CHOICE(?List)
IF R# < 2
   BEEP
ELSE
   GET(BrowseQ, R#)
   SavePos1# = BrowseQ.Pos

   GET(BrowseQ, R#-1)
   SavePos2#   = BrowseQ.Pos
   BrowseQ.Pos = SavePos1#
   PUT(BrowseQ)
   ! Update Table if required

   GET(BrowseQ, R#)
   BrowseQ.Pos = SavePos2#
   PUT(BrowseQ)
   ! Update Table if required
  
   SORT(BrowseQ, BrowseQ.Pos)

   DISPLAY(?List)
END

If you need to update a Table in which the Pos field is supposed to be Unique, then you have to update the previous record with a high value first and then later update it with the correct value after updating the current record.

   GET(BrowseQ, R#)
   SavePos1# = BrowseQ.Pos

   GET(BrowseQ, R#-1)
   SavePos2#   = BrowseQ.Pos
   BrowseQ.Pos = 9999
   PUT(BrowseQ)
   ! Update Table if required

   GET(BrowseQ, R#)
   BrowseQ.Pos = SavePos2#
   PUT(BrowseQ)
   ! Update Table if required

   GET(BrowseQ, R#-1)
   SavePos2#   = BrowseQ.Pos
   BrowseQ.Pos = SavePos1#
   PUT(BrowseQ)
   ! Update Table if required

You could also update the Table only and just refresh the Browse with a BRWn.ResetSort(True) for ABC or a DO BRWn::RefreshPage for Legacy.

RE: Change Record Position by Buttonclick

(OP)
Thanx - works great, just one small problem remains. In cases where browses have more lines than the listbox can display, it starts to scroll.
A record on the first position of the current scroll-view, is not always the first record in the browse.

1 00000000
2 00000000
3 00000000
4 xxxxxxxx (1)
5 xxxxxxxx (2)
6 xxxxxxxx (3)
7 xxxxxxxx (4)
8 00000000
9 00000000

Records marked '0' are not in view at current scrollview.
Records marked 'x' are in visible in browse.

CHOICE() will return position = 1 for record number 4, although it is on position 4 of the browse. Is there any
alternative for CHOICE()?

Thank you once more for taking the time to help me. I really appreciate it. Hopefully other newbs will profit from this.

RE: Change Record Position by Buttonclick

Hi,

Put the following CODE in the 'Control Event Handling After Genereated Code' - Accepted of 'UP' button

-----
    IF POINTER(TestQueue) = 1
        BEEP
    ELSE

        POS# = POINTER(TestQueue)

        GET(TestQueue,POS#-1)
        TempName2 = TQ:NameField

        GET(TestQueue,POS#)
        TempName1 = TQ:NameField

        TQ:NameField = TempName2
        PUT(TestQueue)

        GET(TestQueue,POS#-1)
        TQ:NameField = TempName1
        PUT(TestQueue)

        SELECT(?TestQueue,POS#-1)

    END
------

Put the following CODE in the 'Control Event Handling After Genereated Code' - Accepted of 'Down' button

-----
    IF POINTER(TestQueue) = RECORDS(TestQueue)
        BEEP
    ELSE

        POS# = POINTER(TestQueue)

        GET(TestQueue,POS#+1)
        TempName2 = TQ:NameField

        GET(TestQueue,POS#)
        TempName1 = TQ:NameField

        TQ:NameField = TempName2
        PUT(TestQueue)

        GET(TestQueue,POS#+1)
        TQ:NameField = TempName1
        PUT(TestQueue)

        SELECT(?TestQueue,POS#+1)

    END
-----

Put the following CODE in the 'Control Event Handling After Genereated Code' - NewSelection of '?TestQueue' (This is your listbox for browsing queue)

-----
    GET(TestQueue,CHOICE(?TestQueue))
-----

Hope it works for you.

Bye

RE: Change Record Position by Buttonclick

The Pos field I asked to Update is the field on the Table and not the Queue position. And since you cannot press the Up button on the first line and the Down button on the last line, all records to be shuffled are in the Queue anyway. The CHOICE() is used to just re-get the Queue record.

For Example, if you table contains two fields TBL:No and TBL:Name, the corresponding Queue fields are BrowseQ.TBL:No and BrowseQ.TBL:Name. The Pos field in this case is TBL:No and the only reason you update BrowseQ.TBL:No is to prevent refreshing from file again. If you want you could just update the Table field (TBL:No) and refresh the browse.

Did you check out the SHUFFLER template?

RE: Change Record Position by Buttonclick

(OP)
Great. Many Thanx for all your help - it's up and running now. You should consider recommneding this thread to other newbies, as I have found it to be most helpfull. I figure the task is quite common, too.

So thanx once more!

Andy

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close