nf67 Posted April 9, 2010 Share Posted April 9, 2010 See topic titleAny way to do this?Example:$Choice = MsgBox(4,"Upper / Lower", "Press YES for upper case :: NO for lower case") If $Choice = 6 Then $Letter = "A" Else $Letter = "a" EndIf If $letter = "a" then ;Unfortunately, this is true, regardless of your choice. MsgBox(0,"You picked " & $Letter ,"The condition ( $Letter = ""a"" ) is met!") EndIf Link to comment Share on other sites More sharing options...
Spiff59 Posted April 9, 2010 Share Posted April 9, 2010 See topic title Any way to do this? Example: $Choice = MsgBox(4,"Upper / Lower", "Press YES for upper case :: NO for lower case") If $Choice = 6 Then $Letter = "A" Else $Letter = "a" EndIf If $letter = "a" then ;Unfortunately, this is true, regardless of your choice. MsgBox(0,"You picked " & $Letter ,"The condition ( $Letter = ""a"" ) is met!") EndIf Switch the operand in your comparison from "=" to "==" Link to comment Share on other sites More sharing options...
nf67 Posted April 9, 2010 Author Share Posted April 9, 2010 Thanks, but how do I go about this using the following (a switch statement)? Switch $Letter Case "a" MsgBox(0,"lower case", "a") Case "A" MsgBox(0,"upper case", "A") EndSwitch Link to comment Share on other sites More sharing options...
Spiff59 Posted April 9, 2010 Share Posted April 9, 2010 (edited) There are likley other methods to go about it, but the first that came to mind is: Switch Asc($Letter) Case Asc("a") MsgBox(0,"lower case", "a") Case Asc("A") MsgBox(0,"upper case", "A") EndSwitch Switch Asc($Letter) Case 97 MsgBox(0,"lower case", "a") Case 65 MsgBox(0,"upper case", "A") EndSwitch The second switch, using the actual ascii character values (rather than converting them for each compare) would result in a lot less CPU usage. Edit: The ASCII table is in the appendix of the helpfile. Edit2: Another way to skin your cat (I'm sure there are more...): If StringIsLower($Letter) Then Switch $Letter Case "a" MsgBox(0,"lower case", "a") Case "b" EndSwitch Else Switch $Letter Case "A" MsgBox(0,"UPPER case", "A") Case "B" EndSwitch EndIf Edit3: Or... (although you might want a StringIsAlpha() test in there first): If Asc($Letter) > 90 Then MsgBox(0,"lower case", $Letter) Else MsgBox(0,"UPPER case", $Letter) EndIf Edited April 9, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
nf67 Posted April 9, 2010 Author Share Posted April 9, 2010 (edited) Thanks, used StringIsLower($Letter) , however this is a thing I had actually expected to have an Opt() for Edit: Has this topic unleashed your inner letter checker, Spiff59 ? Edited April 9, 2010 by nf67 Link to comment Share on other sites More sharing options...
ssubirias3 Posted April 9, 2010 Share Posted April 9, 2010 See topic title Any way to do this? Example: $Choice = MsgBox(4,"Upper / Lower", "Press YES for upper case :: NO for lower case") If $Choice = 6 Then $Letter = "A" Else $Letter = "a" EndIf If $letter = "a" then ;Unfortunately, this is true, regardless of your choice. MsgBox(0,"You picked " & $Letter ,"The condition ( $Letter = ""a"" ) is met!") EndIf Hi, your script works perfectly as is!!! I'm guessing you think its not working becase the "text" in the MsgBox(flag, title, text) displays the little a regardless if YES or NO button is pressed. Simply make the "text" section use the $Letter variable like you did in the "title" section of the MsgBox(). For example it should read: MsgBox(0,'You picked ' & $Letter, 'The condition ( $Letter = "' & $Letter & '" ) is met!') Note the use of single quotes makes it easier to read especially when wanting to include double quotes as part of the string. Hope this helps! Link to comment Share on other sites More sharing options...
nf67 Posted April 9, 2010 Author Share Posted April 9, 2010 Sorry Ssubirias, but that's not what I mean.The example I provided isn't case-sensitive; despite the fact that the script checks for "a", it also runs the code when "A" is found.Thanks anyway 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