If Then Else Statement In VB.NET

How to use If Then Else Statement?

Explanation

If Then Else Statement

If Then Else statement is a control structure which executes different set of code statements when the given condition is true or false.
Syntax:
If [Condition] Then
[Statements] Else
[Statements]

In the above syntax when the Condition is true, the Statements after Then are executed.If the condition is false then the statements after the Else part 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
MsgBox("GRADUATED")
Else
MsgBox("NOT GRADUATED")
End If
End Sub
Description:

In the above If Then Else example the marks are entered in TextBox1.When a button is clicked a message GRADUATED is displayed if the condition (>40) is true and NOT GRADUATED if it is false.

Visual Basic Tutorial


Ask Questions

Ask Question