Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Record Position by Buttonclick 2

Status
Not open for further replies.

cathalturi

Programmer
Sep 29, 2003
14
DE
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!
 
...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!!!)
 
Check 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.
 
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.
 
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

 
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?

 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top