If Then Statement in VB.NET
How to use If Then statement?
Explanation
If Then Statement
If Then statement is a control structure which executes a set of code only when the given condition is true.
Syntax:
If [Condition] Then
[Statements]
In the above syntax when the
Condition is true then the
Statements after
Then are
executed.
Example:
Private Sub Button1_Click_1(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
If Val(TextBox1.Text) > 25 Then
TextBox2.Text = "Eligible"
End If
Description:
In the above If Then example the button click event is used to check if the age got using
TextBox1
is greater than
25, if true a message is displayed in
TextBox2