Jump to content

Forcing user to enter 1 of 3 words


Recommended Posts

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.

Link to comment
Share on other sites

  • Developers

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"

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
Link to comment
Share on other sites

  • Developers

you need to explain this.....

Will you have 2 input statements then?

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...