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 


LIST SORT and Numerical DATA

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


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Sat Mar 13, 2004 6:56 am    Post subject: LIST SORT and Numerical DATA Reply with quote

Hi, I am trying to sort a list of data:
example:
8,yadayadayda
9,yadayadayda
10,yadayadayda
11,yadayadayda

and when I apply the LIST SORT Command (vds4) the list becomes like this:

10,yadayadayda
11,yadayadayda
8,yadayadayda
9,yadayadayda

instead of being in numerical order. Is there an easier way to sort the numerical data without adding leading zeros to the numbers?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sat Mar 13, 2004 10:32 am    Post subject: Reply with quote

I don't think so. Any standard "sort" starts with the leftmost
character - which doesn't leave ya many options.

You can make a routine to automatically pad zeros when
your list is loaded though. Wink

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sat Mar 13, 2004 11:22 am    Post subject: Reply with quote

Here's an example using a second unsorted list for editing.
It uses a var you can change to pad the numbers (currently
3 digits).

You shouldn't perform the change directly on a sorted list,
because you don't know if the edited item will be re-inserted
above or below the current index position (sorted lists cannot
use LIST PUT). Wink
_____________________________________________________________
Code:

OPTION FIELDSEP, ","
LIST CREATE, 1, SORTED

LIST LOADTEXT, 1,
"10,yadayadayda
"11,yadayadayda
"8,yadayadayda
"9,yadayadayda

INFO Before padding:@cr()@cr()@text(1)

rem -- desired number length --
%%numlen = 3

rem -- need an unsorted list to work with --
LIST CREATE, 2
LIST ASSIGN, 2, 1

%x = 0
REPEAT
  PARSE "%a", @item(2, %x)
  if @greater(%%numlen, @len(%a))

     rem -- remove number from item --
     LIST PUT, 2, @strdel(@item(2, %x), 1, @len(%a))

     rem -- pad number with zeros --
     REPEAT
       %a = "0"%a
     UNTIL @equal(@len(%a), %%numlen)

     rem -- re-insert number --
     LIST PUT, 2, %a@item(2, %x)
  end
  %x = @succ(%x)
UNTIL @equal(%x, @count(2))

LIST ASSIGN, 1, 2
LIST CLOSE, 2

INFO After padding:@cr()@cr()@text(1)

Cheers, Mac Smile

[EDIT] Removed an extra ";" in the PARSE command.

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361


Last edited by Mac on Thu Mar 18, 2004 1:30 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Sat Mar 13, 2004 11:21 pm    Post subject: Reply with quote

a suggestion...not sure if it is a good one...why don't you start your numbering from 10 onwards (as long as you don't go beyond 99)

serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TSgigs
Newbie


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Tue Mar 16, 2004 3:44 am    Post subject: Reply with quote

Thanks Mac your answers are always swift and to the point.

Serge, also a good suggestion which I would have used if I had control of the start data. Writing a companion program and it's just working with the data that another program outputs so I have to manipulate the data as is.

I was using a @FORMAT(@FDIV(%%var,10000000),8.8) command in a GOSUB routine to do the necessary padding. Was alot simplier then actually adding 0s onto it with a REPEAT command. I would then inturn use @FMUL(%%VAR,10000000) to restore the number. This worked well and good until some non-english versions of windows encountered problems. specifically german version. They defaulted to using a coma for a decimal place instead of a period and this threw the routine off when trying to convert back and remove the 0s. Not really sure as to why it did this. However, end all solution was as follows:

Code:

LIST CREATE,7
LIST ADD,7,"%%BLVL;"|%%BLVL
LIST ADD,7,"%%JLVL;"|%%JLVL
LIST ADD,7,"%%BEXP;"|%%BEXP
LIST ADD,7,"%%JEXP;"|%%JEXP
LIST ADD,7,"%%ZENY;"|%%ZENY
LIST ADD,7,"%%STR;"|%%STR
LIST ADD,7,"%%AGI;"|%%AGI
LIST ADD,7,"%%VIT;"|%%VIT
LIST ADD,7,"%%INT;"|%%INT
LIST ADD,7,"%%DEX;"|%%DEX
LIST ADD,7,"%%LUK;"|%%LUK
%%SUB_COUNTER = 0
REPEAT
   PARSE "%%VAR;%%VALUE",@ITEM(7,%%SUB_COUNTER)
   REPEAT
      IF @GREATER(16,@LEN(%%VALUE))
           %%VALUE = "0"%%VALUE
          END
   UNTIL @EQUAL(@LEN(%%VALUE),16)
   PARSE %%VAR,%%VALUE       
   %%SUB_COUNTER = @SUCC(%%SUB_COUNTER)
UNTIL @EQUAL(%%SUB_COUNTER,@COUNT(7))
LIST CLOSE,7


Later on in the program removing the 0s was extremely simple. @FADD(%%var,0) and it restores the number back to no leading zeros.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TSgigs
Newbie


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Tue Mar 16, 2004 3:54 am    Post subject: Reply with quote

oi! this routine works only VDS environment app not in a compiled exe. *back to drawing board*
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TSgigs
Newbie


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Tue Mar 16, 2004 4:01 am    Post subject: Reply with quote

Very Happy

Scratch that found a work around. Kind of an oddity but here is:

Orignal Problematic Line
Code:
PARSE %%VAR,%%VALUE


New Working Line
Code:
PARSE " "%%VAR,%%VALUE


all is good Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Tue Mar 16, 2004 4:12 am    Post subject: Reply with quote

The PARSE command requires the recipient vars to be
inside quotes (separated by semi-colons if there are
more than one):

PARSE "%%var1", %%ItemToParse

or

PARSE "%%var1; %%var2", %%ItemToParse

I'm surprised it even works like ya have it... Wink

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
TSgigs
Newbie


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Tue Mar 16, 2004 6:22 am    Post subject: Reply with quote

Laughing haha, I know.

I wanted to try it because it made the routine alot easier to write and I am glad it worked. good to know eh?

was the main reason why i posted to code, i hadn't seen any source written like that previously but it definately simplies the process of me having rewrite a list of multiple variables.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Tue Mar 16, 2004 9:56 am    Post subject: Reply with quote

Very interesting... but I'm not exactly sure how it's easier. Wink

When you add the var names to LIST 7, it puts another
"layer" between you and the data.

Adding vars to the list normally (not the quoted names)
should achieve the same results - or am just I missing
something here? Confused LOL, wouldn't be the first time.... Wink

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Tue Mar 16, 2004 3:24 pm    Post subject: Reply with quote

Hey Mac,

FYI, I just used your method of padding leading zeros for a similar purpose & it works nice, thanks Smile.

I kinda thought I could just use something like this:

repeat
%1 = @succ(%1)
info @format(%1,3.0)
until @equal(%1,10)

but i guess you know the result. Sad

moke
Back to top
View user's profile Send private message Send e-mail
TSgigs
Newbie


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Tue Mar 16, 2004 6:46 pm    Post subject: Reply with quote

not using the "quoted" variables on the list in my code would not work the same, because it would return the values of the variables instead the names of the variables. the reason for the quotes is to preverve the variable names for reassigning during the routine. otherwise it would try to write a value to a value and error

ie:

List add,7,%%var1|%%var1

would be replaced with value1|value1

with the quotes

list add,7,"%%var1;"|%%var1

the first portion of the string would return %%var1 as a name and not a value and the second is a value.

not sure if i explained the right.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Wed Mar 17, 2004 12:58 am    Post subject: Reply with quote

moke - glad ya could use it. Wink

TSgigs - Clear as mud... Laughing

I'll just take your word for it. Wink

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
TSgigs
Newbie


Joined: 28 Nov 2000
Posts: 9
Location: Michigan USA

PostPosted: Wed Mar 17, 2004 4:47 am    Post subject: Reply with quote

Confused

In the end your right again Mac,

The routine does not work. It only works in the vds app itself and not in a compiled exe. the " " work around i put in allowed the routine to run but would not write the variables, so I have to scratch the routine and will likely adopt your method. Was trying to avoid rewriting as little code as possible. Will have to anyway lol

Thanks for you help guys.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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