Legal Information
PC Knowledge Base - Using If.....Then.....Else Statements with Opreators in Visual Basic

Good Knowledge Is Good2Use

To effectively control the VB program flow, we shall use If...Then...Else statement together with the conditonal operators and logical operators. The general format for the if...then...else statement is

If conditions Then
VB expressions
Else
VB expressions
End If
* any If..Then..Else statement must end with End If. Sometime it is not necessary to use Else.

Example:

Private Sub OK_Click()
firstnum = Val(usernum1.Text)
secondnum = Val(usernum2.Text)
total = Val(sum.Text)
If total = firstnum + secondnum And Val(sum.Text) <> 0 Then
correct.Visible = True
wrong.Visible = False
Else
correct.Visible = False
wrong.Visible = True
End If
End Sub


Search Knowledge Base Feedback
If you like our web site refer a friend.
Your friends name.
Your friends email address.
Your Name
Your Email Address


© Copyright 1998-1999 GOOD2USE