Sunday, December 19, 2010

If Then Else Statement


The if-then-else statement provides a secondary path of execution when an "if" clause evaluates to false, the ELSE part will be executed.

Syntax:

If <> Then


Block of the statement1


Else


Block of the statement2


End If


If the condition is TRUE block of the statement1 will be executed. If the condition is evaluated FALSE block of the statement2 will be executed.

Example

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


Dim a As String
a = InputBox("Enter text")

If a = "" Then
Me.Close()
Else
MsgBox("Welcome " & a)
End If
End Sub

End Class