Nested If..Then..Else statement is used to check multiple conditions using if then else statements nested inside one another.
Syntax:
If [Condition] Then
If [Condition] Then
[Statements]
Else
[Statements]
Else
[Statements]
In the above syntax when the Condition of the first if then else is true, the second if then else is executed to check another two conditions. If false the statements under the Else part of the first statement is executed.
Example:
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
If Val(TextBox1.Text) >= 40 Then
If Val(TextBox1.Text) >= 60 Then
MsgBox("You have FIRST Class")
Else
MsgBox("You have SECOND Class")
End If
Else
MsgBox("Check your Average marks entered")
End If
End Sub
No comments:
Post a Comment