Sign in to follow this  
Followers 0
SweatyOgre

Forcing user to enter 1 of 3 words

13 posts in this topic

I would like to force the user of my program to enter one of three words in an input box. What would be the best way to go about that?

Here is the code for the inputbox:

$Difficulty = InputBox ("Difficulty", "Enter the difficluty at which you wish to do the pindle runs:", "norm, night, or hell")

The three words are "norm", "night", and "hell" I was thinking a loop that makes the user re-enter the information until they use one of the words, but I'm not sure which loop would be best.

Share this post


Link to post
Share on other sites



something like this ?

Do
   $Difficulty = InputBox ("Difficulty", "Enter the difficluty at which you wish to do the pindle runs:")
Until $Difficulty =  "norm" or $Difficulty =  "night" or $Difficulty =  "hell"

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you, I was trying something with a While...WEnd or an If...Then statement, this is much simpler.

Share this post


Link to post
Share on other sites

if your list gets longer you can also use this trick:

Until StringInStr("|norm|night|hell|","|" & $Difficulty & "|")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

theres lots of ways, one way may be like this

Ask()
Func Ask()
Global $Difficulty = InputBox ("Difficulty", "Enter the difficluty at which you wish to do the pindle runs:", "norm, night, or hell")
Check()
Endfunc


Func Check()

Select

   Case $Difficulty = "norm"
            ContinueNorm()
   Case $Difficulty = "night"
            ContinueNight()
   Case $Difficulty = "hell"
            ContinueHell()
   Case Else
            Ask()
EndSelect

Endfunc


Func ContinueNorm()
EndFunc
Func ContinueHell()
Endfunc
Func ContinueNight()
Endfunc

Does this help at all?


-Brett

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

lol wow!!! am i that slow?? i thought i was the first one to reply :D

Edit: My way wasn't that great either :huh2:

Edited by brett

-Brett

Share this post


Link to post
Share on other sites

What if I wanted to do until 2 conditions were true?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

No, but I want 2 things to be true about an input statement.

Edit: Nevermind, I figured it out, but thanks anyway.

Edited by SweatyOgre

Share this post


Link to post
Share on other sites

No, but I want 2 things to be true about an input statement.

You can use AND instead of OR.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

theres lots of ways, one way may be like this

<Code Removed>

Does this help at all?

The only problem with this is the level of recursion. Try: (watch word wrap)

Dim $Difficulty, $Test

Do
    $Difficulty = InputBox ("Difficulty", "Enter the difficulty at which you wish to do the pindle runs:", "norm, night, or hell")
    If @Error then
         Exit
    Endif
    $Difficulty = StringLower(StringStripWS($Difficulty, 3))
    $Test=StringInStr("|norm|night|hell|","|" & $Difficulty & "|")
    If $Test=0 then
         MsgBox(0,"Invalid Info", "That is not a valid answer.  Please try again."
    Endif
Until $Test > 0 
Select 
Case $Difficulty = "norm"
  ; Do normal
Case $Difficulty = "night"
  ; Do night level
Case $Difficulty = "hell"
  ; Do hell level
EndSelect
Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

[off-topic]

JdeB ever played Diablo II ? thought about it when i saw "Norm", "Night" and "Hell" :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0