I am working on a basic yes no game right now as my first vbscript app and I am worried that there is a more efficient way to write this. My main concern is accounting for lowercase answers and at the end I have to write end end end end end etc, my current solution for multiple answers is writing more if statements but that makes my code longer and require a lot of ends at the final line of code
if a ="No" Then
p = MsgBox("Bye")
Else
if a ="no" Then
p1 = MsgBox("Bye")
Else
b = InputBox("What is your name?")
c = InputBox("Isn't that a good name?(Yes/No)")
if c ="No" Then
d = MsgBox("That's not nice.")
Else
if c ="no" Then
d1 = MsgBox("That's not nice.")
Else
l = MsgBox("It's good that you like it, afterall you are stuck with that name.")end if end if end if end if```
To make it so that it isn't non-CaSe SeNsItIvE you can use the LCase or UCase function to make the inputted string either all upper case with UCase or fully lower case with LCase.
For your case you could do:
c = InputBox("Isn't that a good name?(Yes/No)")
if LCase(c) = "no" Then
MsgBox("That's not nice.")
End If
No matter how the user capitalizes the input this will work.
To better visualize refer to this table:
Input | LCase(input) |
---|---|
nO | no |
No | no |
no | no |
(Make sure that your = "WHATEVER
" is either all in lowercase or uppercase depending if you use LCase or UCase as using the wrong case sensitivity from your function will not make it work)
Also, side note you don't need to make your MsgBox a variable.