If.....Then.....Else Statements

Started by VelMurugan, Jul 24, 2008, 03:29 PM

Previous topic - Next topic

VelMurugan

Using  If.....Then.....Else  Statements  with Operators

To effectively control the VB program flow, we shall use If...Then...Else statement together with the conditional 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