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 


How can I find something SPECIFIC in a list?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
flypaper
Contributor
Contributor


Joined: 19 Oct 2001
Posts: 104

PostPosted: Wed Oct 30, 2002 5:06 pm    Post subject: How can I find something SPECIFIC in a list? Reply with quote

If I have a list with the following for example:

Lewis
Jackson
Smith
Jack

If I do a search for 'Jack' what is the easiest way to make sure that it doesn't hit on jackson?
Back to top
View user's profile Send private message
Skit3000
Admin Team


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

PostPosted: Wed Oct 30, 2002 6:10 pm    Post subject: Reply with quote

Here is a little code.

Code:
list create,1
list loadtext,1
"Lewis
"Jackson
"Smith
"Jack

%%searchstring = Jack
%z = 0
repeat
%z = @succ(%z)
until @equal(@item(1,%z),%%searchstring)

info @item(1)
Back to top
View user's profile Send private message
flypaper
Contributor
Contributor


Joined: 19 Oct 2001
Posts: 104

PostPosted: Wed Oct 30, 2002 7:16 pm    Post subject: Reply with quote

I get your idea, but can't get it to work. Your code seems broken or I'm doing something wrong.

Here is the exact code I'm using:
Code:

%%count = 0
repeat
  %%count = @succ(%%count)
until @equal(@item(1,%%count),@item(list1))


What am I doing wrong?? It just hangs.

EDIT - Never mind, I think I know now.
Back to top
View user's profile Send private message
flypaper
Contributor
Contributor


Joined: 19 Oct 2001
Posts: 104

PostPosted: Wed Oct 30, 2002 7:47 pm    Post subject: Reply with quote

Okay I fixed my error. The very odd thing about this "search" is that it seems to miss about one out of ten times. Never the same name either!?!? I'm cornfused.
Back to top
View user's profile Send private message
Garrett
Moderator Team


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

PostPosted: Wed Oct 30, 2002 9:24 pm    Post subject: Reply with quote

You also need to take into account that there may not be a match. Your
current code may produce a VDS error in your script if no match is found
because it will continue to try searching the list beyond the count of the
list, or it will just keep going in the repeat and never break out of the
repeat. so try this instead:


Code:
%%count = 0
repeat
  %%count = @succ(%%count)
until @equal(@item(1,%%count),@item(list1))@not(@ok())


Adding the @not(@ok()) ok to the UNTIL will tell VDS to stop the repeat if
not ok. When you search beyond the limits of the list, it will not be ok, so
the repeat will be complete if no match is found. Or you can do it like this
also:

Code:
%%count = 0
repeat
  %%count = @succ(%%count)
until @equal(@item(1,%%count),@item(list1))@equal(%%count,@count(1))


-Garrett
Back to top
View user's profile Send private message
Mac
Professional Member
Professional Member


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

PostPosted: Wed Oct 30, 2002 9:28 pm    Post subject: Reply with quote

Code:

LIST CREATE, 1
LIST ADD, 1, "Lewis"
LIST ADD, 1, "Jackson"
LIST ADD, 1, "Smith"
LIST ADD, 1, "Jack"

%%search = "Jack"

%x = 0
REPEAT
  if @equal(%%search, @item(1, %x))
     %%line = @succ(@index(1))
  end
  %x = @succ(%x)
UNTIL @equal(%x, @count(1))
if %line
   INFO Match found at line %%line
else
   INFO No match found...
end

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


Last edited by Mac on Wed Oct 30, 2002 9:37 pm; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Wed Oct 30, 2002 9:28 pm    Post subject: Reply with quote

I modified the code that Skit3000 posted...I couldn't get the code to work either. I re-wrote the repeat section to advance the list when searching. Smile

Code:
  list create,1
  list loadtext,1
"Lewis
"Jackson
"Smith
"Jack

%%find = Smith
%%index = 0
repeat
list seek,1,%%index
%%index = @succ(%%index)
until @equal(@item(1),%%find)
info Match found for %%find at list position @index(1)
list close,1
exit

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Wed Oct 30, 2002 9:29 pm    Post subject: Reply with quote

Oops! Mac beat me to it Exclamation
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Mac
Professional Member
Professional Member


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

PostPosted: Wed Oct 30, 2002 9:30 pm    Post subject: Reply with quote

Lol, and Garrett posted before I did.... Very Happy

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
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Oct 30, 2002 9:32 pm    Post subject: Reply with quote

If possible you can also put a character on the beginning and end of the name and search for that, like:
|Lewis|
|Jackson|
|Smith|
|Jack|

And use @MATCH(1,|Jack|)

To return just the name you can Parse it:
Code:
PARSE "%a;%%Name",@MATCH(1,|Jack|)

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
flypaper
Contributor
Contributor


Joined: 19 Oct 2001
Posts: 104

PostPosted: Thu Oct 31, 2002 3:30 pm    Post subject: Reply with quote

Wow. You guys really rock. Thanks!
Back to top
View user's profile Send private message
Skit3000
Admin Team


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

PostPosted: Thu Oct 31, 2002 6:23 pm    Post subject: Reply with quote

I know why my code doesn't work: the forum has added a space after every line... If you remove it, it will work...

Btw. Tommy, can you adjust this? Some programs need spaces to run proper (like the Tetris example I've posted a while ago, which you didn't got to work because the spaces were removed...)
Back to top
View user's profile Send private message
Skit3000
Admin Team


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

PostPosted: Thu Oct 31, 2002 6:29 pm    Post subject: Reply with quote

SnarlingSheep, if you use the parse function, and only want to parse the second thing, use it like this:

Code:
parse ";%%name",@match(1,|Jack|)


So you don't have to use an other variable in front of %%name.
Back to top
View user's profile Send private message
Mac
Professional Member
Professional Member


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

PostPosted: Thu Oct 31, 2002 6:32 pm    Post subject: Reply with quote

LIST LOADTEXT is real sensitive to the end of line chars Skit.

LIST ADD usually works OK for copy/paste. 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
Garrett
Moderator Team


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

PostPosted: Thu Oct 31, 2002 6:41 pm    Post subject: Reply with quote

You guys do realize that your parse routine up there will return Jack| don't you? You only asked it to parse the first | and not the second, so the second | will become part of the results.

Code:
parse "%%Null;%%Name:%%Null",@match(1,|Jack|)


would return just "Jack".


-Garrett
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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