If Not Integer.TryParse(Val(TextBox1.Text), intPin(0)) _
AndAlso Val(TextBox1.Text) >= intMinPin(0) _
AndAlso Val(TextBox1.Text) <= intMaxPin(0) Then
MsgBox("Enter a number between 7 and 9.", MsgBoxStyle.OkOnly, "PIN1")
Return False
End If
Be very careful when using negations (Not) in compound
conditionals. Two things to watch out for:
(1) The "Not" applies to the immediately following
condition, but doesn't apply to the condition after
the conjunction/disjunction. The "Not" must also
appear there if what is desired is to test for both
conditions being untrue. Your compound conditional
is asking: "If the TryParse fails AND if the number
is within the valid range ..."
(2) When using tests for negation (Not) you usually
have to use a disjunction (OrElse), not a conjunction
(AndAlso). When testing for true conditions you usually
are asking "If condition1 is true AND if condition2 is
true then do x". But when testing for negations you usually
are asking "If condition1 is NOT true OR if condition2 is
NOT true then do x".
For example:
If Not Integer.TryParse(Val(TextBox1.Text), intPin(0)) _
OrElse Not Val(TextBox1.Text) >= intMinPin(0) _
OrElse Not Val(TextBox1.Text) <= intMaxPin(0) Then
MsgBox("Enter a number between 7 and 9.", MsgBoxStyle.OkOnly, "PIN1")
Return False
End If
- Wayne