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


Joined: 19 Oct 2001 Posts: 104
|
Posted: Wed Oct 30, 2002 5:06 pm Post subject: How can I find something SPECIFIC in a list? |
|
|
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 |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Wed Oct 30, 2002 6:10 pm Post subject: |
|
|
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 |
|
 |
flypaper Contributor


Joined: 19 Oct 2001 Posts: 104
|
Posted: Wed Oct 30, 2002 7:16 pm Post subject: |
|
|
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 |
|
 |
flypaper Contributor


Joined: 19 Oct 2001 Posts: 104
|
Posted: Wed Oct 30, 2002 7:47 pm Post subject: |
|
|
| 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 |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Wed Oct 30, 2002 9:24 pm Post subject: |
|
|
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 |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Oct 30, 2002 9:28 pm Post subject: |
|
|
| 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  _________________ 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 |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Wed Oct 30, 2002 9:28 pm Post subject: |
|
|
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.
| 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 |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Wed Oct 30, 2002 9:29 pm Post subject: |
|
|
Oops! Mac beat me to it  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Oct 30, 2002 9:30 pm Post subject: |
|
|
Lol, and Garrett posted before I did....
Cheers, Mac  _________________ 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 |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Oct 30, 2002 9:32 pm Post subject: |
|
|
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 |
|
 |
flypaper Contributor


Joined: 19 Oct 2001 Posts: 104
|
Posted: Thu Oct 31, 2002 3:30 pm Post subject: |
|
|
| Wow. You guys really rock. Thanks! |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Thu Oct 31, 2002 6:23 pm Post subject: |
|
|
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 |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Thu Oct 31, 2002 6:29 pm Post subject: |
|
|
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 |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Oct 31, 2002 6:32 pm Post subject: |
|
|
LIST LOADTEXT is real sensitive to the end of line chars Skit.
LIST ADD usually works OK for copy/paste.
Cheers, Mac  _________________ 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 |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Oct 31, 2002 6:41 pm Post subject: |
|
|
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 |
|
 |
|