Checking one variable against a list

Posted by ErockMahan on Fri 16 Jul 2010 10:45 PM — 3 posts, 16,593 views.

#0
I have a list of people I want to perform a seperate action against. I store the list in @omit and seperate each name by a space (but I can change that if it helps). When it comes time to run the alias (something simple like 'reward *') it does the following:

bit = "@omit"
omit = Split(bit, " ")

For u = 0 to Ubound(omit)
if "%1"=(omit(u)) then
world.send "tell %1 you get NOTHING!"
else
world.send "tell %1 you get IT ALL!"
end if
Next


It looks like it should work, but it is checking against EVERY instance of the string instead of finding it once and moving on. I'd rather it checked once and then stopped...
USA #1
I'm not terribly familiar with VBscript, but you should be able to use Exit For from within the loop.

bit = "@omit"
omit = Split(bit, " ")

  For u = 0 to Ubound(omit)
    if "%1"=(omit(u)) then
      world.send "tell %1 you get NOTHING!"
      Exit For ' put this where you want to break out of the loop
    else
      world.send "tell %1 you get IT ALL!"
    end if
  Next


However I question whether you really mean what this code is doing. You're going over the list, and for each one, you send "...IT ALL!" or "...NOTHING!" depending on if there's a match. What I think you meant is this:

bit = "@omit"
omit = Split(bit, " ")
found = False

  For u = 0 to Ubound(omit)
    if "%1"=(omit(u)) then
      world.send "tell %1 you get NOTHING!"
      found = True
      Exit For
    end if
  Next

If found = False Then
  world.send "tell %1 you get IT ALL!"
End If


I don't know how much this could be condensed or clarified. Still, I think it would work.
Amended on Fri 16 Jul 2010 10:55 PM by Twisol
#2
You nailed it. Thanks a ton!