forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[resolved] Moving items in a list up and down

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
DW
Contributor
Contributor


Joined: 21 Mar 2003
Posts: 175
Location: UK

PostPosted: Sat Jun 25, 2005 8:08 pm    Post subject: [resolved] Moving items in a list up and down Reply with quote

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
View user's profile Send private message
ShinobiSoft
Professional Member
Professional Member


Joined: 06 Nov 2002
Posts: 790
Location: Knoxville, Tn

PostPosted: Sat Jun 25, 2005 8:56 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun Jun 26, 2005 5:38 am    Post subject: Reply with quote

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
View user's profile Send private message
DW
Contributor
Contributor


Joined: 21 Mar 2003
Posts: 175
Location: UK

PostPosted: Tue Jun 28, 2005 7:10 pm    Post subject: Reply with quote

Thanks guy I managed to sort out the problem with the info you gave me.

Thanks alot.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group