i542 Posted December 23, 2007 Share Posted December 23, 2007 Howdie,I have this piece of codeFunc _Talk($Input) Switch $Input Case "Hi", "Greetings" Return "Hello" EndSwitch EndFunc (Shorten).So, now, if I run it (with inputbox & stuff, of course) it only responds on "Hi", not on "Hi.", "Hi?" or "Hi!". I know it could be made by using If and StringInStr but that is really long and unreadable. Switch (or Select) is simple and compact I would very appreciate your solution/response/howto (if you have it, of course).What Doesn't WorkI tried this but they won't work:Func _Talk($Input) Switch $Input Case "Hi" OR "Greetings" Return "Hello" EndSwitch EndFuncThat would always return "Hello", eg. "What's Up?" "Hello"Thanks! i542 I can do signature me. Link to comment Share on other sites More sharing options...
covaks Posted December 23, 2007 Share Posted December 23, 2007 Still involves a messy "String" function, which I'm guessing you want to stay away from. But this is how I might do it. Msgbox(1,"",_Talk(InputBox("","Hello"))) Func _Talk($Input) Select Case StringRegExp($Input,"Hi?") OR StringRegExp($Input,"Greetings?") Return "Hello" EndSelect Return "Fine, don't say Hi." EndFunc Link to comment Share on other sites More sharing options...
i542 Posted December 23, 2007 Author Share Posted December 23, 2007 (edited) Still involves a messy "String" function, which I'm guessing you want to stay away from. But this is how I might do it. Msgbox(1,"",_Talk(InputBox("","Hello"))) Func _Talk($Input) Select Case StringRegExp($Input,"Hi?") OR StringRegExp($Input,"Greetings?") Return "Hello" EndSelect Return "Fine, don't say Hi." EndFuncYes, I tried it, but it won't work . Thanks on answer. Edited December 23, 2007 by i542 I can do signature me. Link to comment Share on other sites More sharing options...
covaks Posted December 23, 2007 Share Posted December 23, 2007 What won't work about it? It responds on "Hi", "Hi!", "Hi.", and "Hi?" just like you asked. Link to comment Share on other sites More sharing options...
i542 Posted December 23, 2007 Author Share Posted December 23, 2007 What won't work about it? It responds on "Hi", "Hi!", "Hi.", and "Hi?" just like you asked.Yeees, but on "How are you" it respond by "Hi" I can do signature me. Link to comment Share on other sites More sharing options...
covaks Posted December 23, 2007 Share Posted December 23, 2007 See if this works: Msgbox(1,"",_Talk(InputBox("","Hello"))) Func _Talk($Input) Select Case StringRegExp($Input,"^Hi[.!?]?$") OR StringRegExp($Input,"^Greetings[.!?]?$") Return "Hello" EndSelect Return "Fine, don't say Hi." EndFunc Link to comment Share on other sites More sharing options...
i542 Posted December 24, 2007 Author Share Posted December 24, 2007 See if this works: Msgbox(1,"",_Talk(InputBox("","Hello"))) Func _Talk($Input) Select Case StringRegExp($Input,"^Hi[.!?]?$") OR StringRegExp($Input,"^Greetings[.!?]?$") Return "Hello" EndSelect Return "Fine, don't say Hi." EndFuncYes that's the one! Thanks! I can do signature me. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now