Newb Question: "Or" command, case sensitivity or aliases
-
Friday, May 25, 2012 5:16 AM
So I am writing my first program. I can't figure out how to make input not case sensitive, or at least put in different aliases. This is what I have so far :
TextWindow.WriteLine("Please enter your selection:") selection = TextWindow.Read() TextWindow.WriteLine("You selected " +selection) TextWindow.WriteLine("is this correct. Y or N") confirmation = TextWindow.Read() If confirmation = "N" Or "No" Or "NO" Or "no" Or "n" Then GOTO START EndIf If confirmation = "Y" Or "y" Or "yes" Or "Yes" Or "YES" Then TextWindow.WriteLine("Very well, I will select a restraunt in " +selection) EndifIt doesn't seem to be picking up the other versions of input I want to be a match.
Any suggestions?
Thanks,
Jeff
All Replies
-
Friday, May 25, 2012 6:15 AMAnswerer
Hello ElChefeJefe!
I've got 2 suggestions for you:
You can use Text.ConvertToUpperCase() or Text.ConvertToLowerCase() to force the entire letters within a string to become either capital or minuscule.
The other one is to use TextWindow.ReadKey() rather than the common TextWindow.Read() if you just need a single key character as input. This way, you spare the user the obligation to push an additional <Enter> key all the time!
I have a subroutine snippet which I use on some of my codes when I wish a 'Yes' confirmation from a user. It returns OK = "True" if the user hit <Y> or <Enter>, otherwise it returns OK = "False". Perhaps you may wish to modify it to better fit your own code. :-D
Sub AskConfirm TextWindow.WriteLine("Hit <Y> or <Enter> to confirm it,") TextWindow.WriteLine("or any other key to cancel it!") key = Text.ConvertToUpperCase( TextWindow.ReadKey() ) If key = "Y" Or key = Text.GetCharacter(13) Then OK = "True" ElseIf key = Text.GetCharacter(27) Then Program.End() Else OK = "False" EndIf EndSub- Edited by GoToLoopEditor Friday, May 25, 2012 6:17 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:19 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:21 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:23 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 7:01 AM
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Thursday, October 11, 2012 6:20 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Friday, October 19, 2012 8:49 PM
-
Friday, May 25, 2012 6:31 AM
Another way;
start:
TextWindow.WriteLine("Please enter your selection:")
selection = TextWindow.Read()
TextWindow.WriteLine("You selected " +selection)
TextWindow.WriteLine("is this correct. Y or N")
confirmation = TextWindow.Read()
CN= Text.GetCharacterCode(text.ConvertToLowerCase(confirmation)) '<---------
' Text.GetCharacterCode returns first letter's code number exam; not ....n(110) niet...n(110) yes....y(121) yeh!...y(121)If CN= 110 Then ' n =110 '<---------
GOTO START
elseIf CN=121 Then ' y=121 '<---------
TextWindow.WriteLine("Very well, I will select a restraunt in " +selection)
Endif*First step; convert to lowercase
*second step; gets CharacterCode
- Edited by NaochanON Friday, May 25, 2012 6:33 AM
- Edited by NaochanON Friday, May 25, 2012 6:36 AM mistake corrected
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Thursday, October 11, 2012 6:20 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Friday, October 19, 2012 8:49 PM
-
Friday, May 25, 2012 6:47 AMAnswerer
Taking a longer glance on your code, I've spotted you are a little astray on how to use the conditional operators correctly (both relational & logical ones). Almost all operators demand 2 operands.
You can't simply compare a variable to many things at once. If you need to compare something to many values, you have to re-type it for each one!
So the line -> If confirmation = "N" Or "No" Or "NO" Or "no" Or "n" Then
should be -> If confirmation = "N" Or confirmation = "No" Or confirmation = "NO" Or confirmation = "no" Or confirmation = "n" Then
Of course, if you follow my advice on using confirmation = Text.ConvertToUpperCase( TextWindow.ReadKey() ), for the line above you'd just need to write -> If confirmation = "N" Then
You can also take a look in this thread here (scroll all the way down), where I've already explained, with more details, the same thing for Alex Wetton.
Laterz!!!
- Edited by GoToLoopEditor Friday, May 25, 2012 6:48 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:50 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:55 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:57 AM
- Edited by GoToLoopEditor Friday, May 25, 2012 6:58 AM
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Thursday, October 11, 2012 6:20 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Friday, October 19, 2012 8:49 PM
-
Friday, May 25, 2012 1:26 PMThanks everyone, this helps a lot.

