[02/03] Comparing strings (NEWB ALERT)
Hey guys, really newbish question here, but this book isnt helping me much in my plight. So, I'm trying to make a program that will help my classmates study their vocab for school (I'm getting extra credit for it! :D) and my code does not do what I want it to. I've set it up so that it compares the two strings (The answer, and the input) like so:
answer = "*Whatever the answer is here, it's randomly generated based on a number, I have like, 125 if/then statements based on random numbers >_>*"
Code:
input = Convert.ToString(Me.txtAnswer.Text)
If answer.ToUpper = input.ToUpper Then
Points = Points + 1
Me.picPass.Visible = True
Me.picFail.Visible = False
Else
Points = Points
Me.picFail.Visible = True
Me.picPass.Visible = False
End If
And this if/then always defaults to the false, because I always see the red checkmark, which indicates a fail. Thanks for your help!
Re: [02/03] Comparing strings (NEWB ALERT)
First of all, why do you need to convert a String to a String?
Quote:
Code:
input = Convert.ToString(Me.txtAnswer.Text)
It doesn't automatically default to False. It compares the two strings and if they are not the same it will show the red check mark. If you see the red check mark then obviously your two strings are not the same. Do you actually know what your two strings contain or are you just assuming? Presumably you are just assuming. You need to actually look at answer.ToUpper and input.ToUpper and see what values they contain. At least one of them will not be what you think itis, otherwise your If block condition would evaluate to True.
Re: [02/03] Comparing strings (NEWB ALERT)
hehe, yeah, I got kinda frusterated and started just doing unessicary things that I thought could help, I'll get right on to your suggestions though, thanks.
Yay, it works, I figured out that, once I clicked "Start" the answer and the root variables got out of sync, so every answer I tried was wrong, thanks so much for the debugging trick :D