| View previous topic :: View next topic |
| Author |
Message |
DW Contributor

Joined: 21 Mar 2003 Posts: 175 Location: UK
|
Posted: Sat Jun 25, 2005 8:08 pm Post subject: [resolved] Moving items in a list up and down |
|
|
Hi, again,
Ok now im trying to move items in a list up and down using buttons.
the code i have is;
| Code: |
:BITBTN16BUTTON
%%_ERROR = BITBTN16BUTTON
%%SAVED = 0
REM MOVE ITEMS UP THE LIST.
if @greater(@count(list1),1)
if @not(@equal(@index(list1),0))
%%DATA = @item(list1)
list delete,list1
list seek,list1,@fsub(@index(list1),1)
list insert,list1,%%DATA
list seek,list1,@index(list1)
else
info This item is already at the top.
end
end
goto evloop
:BITBTN17BUTTON
%%_ERROR = BITBTN17BUTTON
%%SAVED = 0
REM MOVE ITEMS DOWN THE LIST.
REM THIS FUNCTION HAS A BUG THAT CAUSES EXTRA BLANK LINES TO BE CREATED
REM AT THE END OF THE LIST, ALSO MOVEING BLANK LINES CAUSES A CRASH.
IF @EQUAL(@ITEM(LIST1),)
GOTO EVLOOP
END
if @greater(@count(list1),1)
if @equal(@index(list1),@fsub(@count(list1),0))
info This item is already at the bottom.
ELSE
%%DATA = @item(list1)
list delete,list1
list seek,list1,@fadd(@index(list1),1)
if @equal(@index(list1),@fsub(@count(list1),1))
list add,list1,
end
list insert,list1,%%DATA
list seek,list1,@index(list1)
end
end
goto evloop |
This code is buggy, the up works fine, but going down the item never gets there.
any ideas? |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sat Jun 25, 2005 8:56 pm Post subject: |
|
|
Check this out::
| Code: |
dialog create,Demo,-1,0,300,300
dialog add,LIST,list1,5,5,210,290
dialog add,BUTTON,BITBTN16,5,225,70,30,Up
dialog add,BUTTON,BITBTN17,40,225,70,30,Down
dialog show
gosub Refresh
:EVLOOP
wait event
%E = @event()
goto %E
:BITBTN16BUTTON
%%_ERROR = BITBTN16BUTTON
%%SAVED = 0
REM MOVE ITEMS UP THE LIST.
if @greater(@count(list1),1)
if @not(@equal(@index(list1),0))
%%DATA = @item(list1)
%%idx = @index(list1)
if @equal(%%idx,@pred(@count(list1)))
rem Very last item
list delete,list1
list seek,list1,@index(list1)
list insert,list1,%%DATA
list seek,list1,@pred(@index(list1))
else
list delete,list1
list seek,list1,@pred(@index(list1))
list insert,list1,%%DATA
list seek,list1,@pred(@index(list1))
end
else
info This item is already at the top.
end
end
goto evloop
:BITBTN17BUTTON
%%_ERROR = BITBTN17BUTTON
%%SAVED = 0
REM MOVE ITEMS DOWN THE LIST.
REM THIS FUNCTION HAS A BUG THAT CAUSES EXTRA BLANK LINES TO BE CREATED
REM AT THE END OF THE LIST, ALSO MOVEING BLANK LINES CAUSES A CRASH.
IF @EQUAL(@index(LIST1),-1)
GOTO EVLOOP
END
if @greater(@count(list1),0)
if @equal(@index(list1),@pred(@count(list1)))
info This item is already at the bottom.
ELSE
%%DATA = @item(list1)
%%idx = @index(list1)
if @equal(%%idx, @diff(@count(list1),2))
rem this is the item before the very last one
list delete,list1
list add,list1,%%DATA
list seek,list1,@succ(%%idx)
else
rem This handles all other items
list delete,list1
list seek,list1,@succ(@index(list1))
list insert,list1,%%DATA
list seek,list1,@pred(@index(list1))
end
end
end
goto evloop
:CLOSE
exit
:Refresh
%x = 0
list clear,list1
repeat
list add,list1,List Item @succ(%x)
%x = @succ(%x)
until @equal(%x,20)
exit
|
That what yer lookin for? _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sun Jun 26, 2005 5:38 am Post subject: |
|
|
Here's an old example that works, but may need some adjustment to
be usable in VDS 5:
GT-ListExample.dsc
http://www.vdsworld.com/download.php?id=96
If the link doesn't work, look in the source code section of the main site
here and look for GT-ListExample.dsc
-Garrett |
|
| Back to top |
|
 |
DW Contributor

Joined: 21 Mar 2003 Posts: 175 Location: UK
|
Posted: Tue Jun 28, 2005 7:10 pm Post subject: |
|
|
Thanks guy I managed to sort out the problem with the info you gave me.
Thanks alot. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|