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 


Lists joining...

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Capinha
Newbie


Joined: 19 Oct 2006
Posts: 13
Location: Portugal

PostPosted: Fri Jan 25, 2008 6:10 pm    Post subject: Lists joining... Reply with quote

Here I am struggling with lists again...
Can someone suggest-me the best (or at least a) way to paste a list in the existing lines of the previous list, and if possible right adjusted. Kind a like putting as a column.

ex.:
List 1
Hello
Hellox
Helloxx

List 2
Good
Goody
Goodyy

List 3
Evening
Eveningz
Eveningzz

Desired result:


The major problem to me is the adjustment to right of the several columns to include... I would then pretend to export this info to an text file, so I think that using Table dialog element isn't a possible solution...

Any suggestion?

Cheers,
César Capinha

_________________
César Capinha
Back to top
View user's profile Send private message Send e-mail
briguy
Contributor
Contributor


Joined: 09 Aug 2007
Posts: 79

PostPosted: Fri Jan 25, 2008 8:56 pm    Post subject: Reply with quote

The following example is a very simple solution. It does not count for different item amounts in the different list. Maybe this will get you on your way though.

Code:

   title list
   dialog CREATE,New Dialog,-1,0,549,539
   rem *** Modified by Dialog Designer on 1/25/2008 - 15:29 ***
   dialog ADD,LIST,LIST1,34,31,108,144
   dialog ADD,LIST,LIST2,33,158,99,144
   dialog ADD,LIST,LIST3,33,275,105,144
   dialog ADD,TABLE,TABLE1,207,32,360,144,Column 1[80]|Column 2[80]|Column 3[80]
   dialog ADD,TEXT,TEXT1,17,32,,,list1
   dialog ADD,TEXT,TEXT2,16,159,,,list2
   dialog ADD,TEXT,TEXT3,16,277,,,list3
   dialog ADD,TEXT,TEXT4,188,32,,,into table
   dialog ADD,LIST,LIST4,384,33,360,120
   dialog ADD,TEXT,TEXT5,364,33,,,into list
   dialog ADD,BUTTON,BUTTON1,207,397,106,24,Merge to table
   dialog ADD,BUTTON,BUTTON2,384,398,106,24,Merge to list
   dialog SHOW

   list add,list1,Hello
   list add,list1,Hellox
   list add,list1,Helloxx

   list add,list2,Good
   list add,list2,Goody
   list add,list2,Goodyy

   list add,list3,Evening
   list add,list3,Eveningz
   list add,list3,Eveningzz



:Evloop
   wait event
   goto @event()



:BUTTON1BUTTON
   %%countoflist1 = @count(list1)
   %a = 0
   repeat
      list add,table1,@item(list1,%a)@tab()@item(list2,%a)@tab()@item(list3,%a)
      %a = @sum(%A,1)
   until @equal(%A,%%countoflist1)
   goto evloop

:BUTTON2BUTTON
   # chr(32) is a space @tab() is a tab separator
   # a tab is used for a space----- list add,list4,@item(list1,1)@tab()@item(list2,1)@tab()@item(list3,1)

   %%countoflist1 = @count(list1)
   %a = 0
   repeat
      # a tab is used for a space----- list add,list4,@item(list1,%a)@tab()@item(list2,%a)@tab()@item(list3,%a)
      list add,list4,@item(list1,%a)@chr(32)@item(list2,%a)@chr(32)@item(list3,%a)
      %a = @sum(%A,1)
   until @equal(%A,%%countoflist1)
   goto evloop

:Close
   exit
Back to top
View user's profile Send private message
Capinha
Newbie


Joined: 19 Oct 2006
Posts: 13
Location: Portugal

PostPosted: Sat Jan 26, 2008 9:18 am    Post subject: Reply with quote

Hello briguy,

Thanks for your reply. It works very well, but I still have a doubt.
What If the number of lists to join are unknown when writing the code?
Is there a way of doing this a list at the time?
Because when I do it the added recors always go to a new line, instead of pasting in the existing ones.
(the @tab works just fine, and the lists have always the same number of records).

Regards

César
Back to top
View user's profile Send private message Send e-mail
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sat Jan 26, 2008 3:45 pm    Post subject: Reply with quote

Hi César,

Take a look at this part of briguy's code:

Code:
   %%countoflist1 = @count(list1)
   %a = 0
   repeat
      # a tab is used for a space----- list add,list4,@item(list1,%a)@tab()@item(list2,%a)@tab()@item(list3,%a)
      list add,list4,@item(list1,%a)@chr(32)@item(list2,%a)@chr(32)@item(list3,%a)
      %a = @sum(%A,1)
   until @equal(%A,%%countoflist1)


The @count() function always returns the number of lines in a list, in this case, list 1. The last line loops the list add command just as many times before the %a variable is the same number as the item count in list 1. So if list 1 contains 15 lines, the loop will be repeated 15 times as well. If the list contains 500 rows, it gets repeated 500 times. Smile

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Sun Jan 27, 2008 2:16 am    Post subject: Reply with quote

I've been playing with the example code and changed it so it can handle lists of different lengths.

Code:
  title List Example

  DIALOG CREATE,List Example,-1,0,414,539
  DIALOG ADD,LIST,LIST1,34,31,108,140
  DIALOG ADD,LIST,LIST2,33,158,99,140
  DIALOG ADD,LIST,LIST3,33,275,105,140
  DIALOG ADD,TABLE,TABLE1,207,32,348,144,Column 1[80]|Column 2[80]|Column 3[80]
  DIALOG ADD,TEXT,TEXT1,17,32,,13,List 1
  DIALOG ADD,TEXT,TEXT2,16,159,,13,List 2
  DIALOG ADD,TEXT,TEXT3,16,277,,13,List 3
  DIALOG ADD,TEXT,TEXT4,188,32,,13,Merged Table
  DIALOG ADD,LIST,LIST4,384,33,348,120
  DIALOG ADD,TEXT,TEXT5,364,33,,13,Merged List
  DIALOG ADD,BUTTON,Table,180,275,106,24,Merge to table
  DIALOG ADD,BUTTON,List,357,275,106,24,Merge to list
  dialog SHOW

  list add,list1,Hello
  list add,list1,Hellox
  list add,list1,Helloxx

  list add,list2,Good
  list add,list2,Goody
  list add,list2,Goodyy
  list add,list2,Good4
  list add,list2,Good5

  list add,list3,Evening
  list add,list3,Eveningz
  list add,list3,Eveningzz


:Evloop
  wait event
  goto @event()


:TableBUTTON
  gosub ListCount
  %a = 0
  repeat
    # Insert a space for extra items if another list is longer
    if @greater(@succ(%a),@count(list1))
      %%i1 = " "
    else
      %%i1 = @item(list1,%a)
    end
    if @greater(@succ(%a),@count(list2))
      %%i2 = " "
    else
      %%i2 = @item(list2,%a)
    end
    if @greater(@succ(%a),@count(list3))
      %%i3 = " "
    else
      %%i3 = @item(list3,%a)
    end
    list add,table1,%%i1@tab()%%i2@tab()%%i3
    %a = @sum(%A,1)
  until @equal(%A,%%countoflist)
  goto evloop


:ListBUTTON
  gosub ListCount
  %a = 0
  repeat
    # Insert a tab for extra items if another list is longer
    if @greater(@succ(%a),@count(list1))
      %%i1 = @tab()
    else
      %%i1 = @item(list1,%a)
    end
    if @greater(@succ(%a),@count(list2))
      %%i2 = @tab()
    else
      %%i2 = @item(list2,%a)
    end
    if @greater(@succ(%a),@count(list3))
      %%i3 = @tab()
    else
      %%i3 = @item(list3,%a)
    end
    # Insert a tab between each item on same row
    list add,list4,%%i1@tab()%%i2@tab()%%i3
    %a = @sum(%A,1)
  until @equal(%A,%%countoflist)
  goto evloop


:ListCount
  # Get the item count of the longest list
  list create,5
  list add,5,@count(list1)
  list add,5,@count(list2)
  list add,5,@count(list3)
  list sort,5
  list reverse,5
  list seek,5,0
  %%countoflist = @item(5)
  list close,5
  exit
 

:Close
  exit


Skit, César was asking about the number of lists, not number of items in a list.

César, catering for an unknown number of lists is easy enough, but you won't be able to easily use a dialog table. You'd just need to loop for each list. I'll whip up an example for you...

_________________
cheers

Dave
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Sun Jan 27, 2008 3:17 am    Post subject: Reply with quote

Capinha wrote:
What If the number of lists to join are unknown when writing the code?

César, here's an example that works with an unknown number of lists.

It assumes that the lists are in sequential order with no gaps in the list numbers. It will stop looping on the first non-existant list number it finds. So lists should be numbered sequentially, like 1, 2, 3, 4. If lists are 1, 2, 5, 6 it will stop when it gets to 3 because there is no list number 3. Of course you can change it to start at any number, like 3, 4, 5, 6, 7 etc. if you want to use lists 1 and 2 for something else.

Code:
#-----------------------------------------------------------------------------------
# create a bunch of lists (can be as few or as many as needed, up to the VDS limit)

  list create,1
  list add,1,Hello
  list add,1,Hellox
  list add,1,Helloxx

  list create,2
  list add,2,Good
  list add,2,Goody
  list add,2,Goodyy

  list create,3
  list add,3,Evening
  list add,3,Eveningz
  list add,3,Eveningzz

  list create,4
  list add,4,WooHoo
  list add,4,WooHoob
  list add,4,WooHoobb

  list create,5
  list add,5,Woop
  list add,5,Woopq
  list add,5,Woopqq

  list create,6
  list add,6,Bad
  list add,6,Badc
  list add,6,Badcc

#-----------------------------------------------------------------------------------
# main code

  title List Example

  #define function,ListExist

  DIALOG CREATE,List Example,-1,0,414,190
  DIALOG ADD,TEXT,TEXT5,17,32,60,13,Merged List
  DIALOG ADD,LIST,SHOWLIST,36,32,348,120
  DIALOG ADD,BUTTON,LIST,11,275,105,22,Merge to list
  dialog SHOW


:Evloop
  wait event
  goto @event()

 
:ListBUTTON
  %%countoflist1 = @count(1)
  %A = 0
  repeat
    %%Item =
    %B = 1
    while @ListExist(%B,)
      if %%Item
        %%Item = %%Item" "@tab()@item(%B,%A)
      else
        %%Item = @item(%B,%A)
      end
      %B = @succ(%B)
    wend
    list add,SHOWLIST,%%Item
    %A = @succ(%A)
  until @equal(%A,%%countoflist1)
  goto evloop


:Close
  exit


:ListExist
  #-----------------------------------------------------------------------------------
  # Returns 1 if a List exists. SYNTAX %x = @ListExist(<list>[,<existing-errortrap>])
  #  If you are using 'option errortrap' in your script you must use the
  #  optional 2nd parameter so your existing error trap option will be reset
  #  when the function exits.
  #  OK is unchanged
  #-----------------------------------------------------------------------------------
  if @not(%1)
    # Missing argument(s) to function
    error 11
    exit
  end
  option errortrap,listexisterror
  if @count(%1)
    %x = 1
  else
  :ListExistError
    %x =
  end
  option errortrap,%2
  exit %x

_________________
cheers

Dave
Back to top
View user's profile Send private message
Capinha
Newbie


Joined: 19 Oct 2006
Posts: 13
Location: Portugal

PostPosted: Mon Jan 28, 2008 9:23 pm    Post subject: Reply with quote

Thank you all for your explanations, they were all very helpful.
I implemented the repeat process to append each list record in the corresponding line.
The alignment problem was solved using the pad function of the String.dll library. I've transformed all records to the same extent so the alignment stooped being a problem.

This is an example of the output (in portuguese).



Cheers.

César

_________________
César Capinha
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    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