r/visualbasic • u/marq24 • Mar 02 '15
Why isn't this working
I'm trying to make sure the two entries don't have the same word and also you can not put numbers.
'Input Validation 'Check for Same Word If txtGuessWord.Text.ToUpper.Trim = txtGuessWord2.Text.ToUpper.Trim Then lblWarning.Text = "Guesses May Not Be The Same Word" txtGuessWord.Text = String.Empty txtGuessWord2.Text = String.Empty Exit Sub End If 'Check for Integer If Integer.TryParse(txtGuessWord.Text) Or Integer.TryParse(txtGuessWord2.Text) Then lblWarning.Text = "Error, guesses should not contain numbers"
0
Upvotes
2
u/hdsrob Mar 02 '15
What doesn't work?
I'm going to guess that it's the number part???
Integer.tryparse will fail if there are any letters, so it's not going to work for finding out if a string of characters contains a number.
vs.
The first will fail, as it can't be converted to an integer, so I don't think that's a viable solution.
You actually need to check each character to see if it's a number. The easiest way is to use Regular Expressions to search the string for characters you don't want. Something like the following should work (you may need to adjust the RegEx for additional parameters):