[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Checking one variable against a list
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Checking one variable against a list

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by ErockMahan   (65 posts)  [Biography] bio
Date Fri 16 Jul 2010 10:45 PM (UTC)  quote  ]
Message
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...
[Go to top] top

Posted by Twisol   USA  (1,476 posts)  [Biography] bio
Date Fri 16 Jul 2010 10:54 PM (UTC)  quote  ]

Amended on Fri 16 Jul 2010 10:55 PM (UTC) by Twisol

Message
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.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by ErockMahan   (65 posts)  [Biography] bio
Date Thu 22 Jul 2010 02:39 PM (UTC)  quote  ]
Message
You nailed it. Thanks a ton!
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


359 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]