If Then Statement in VB.NET

How to use If Then statement?


If Then Statement

If Then statement is a control structure which executes a set of code only when the given condition is true.
If [Condition] Then

In the above syntax when the Condition is true then the Statements after Then are executed.
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

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

Visual Basic Tutorial

Ask Questions

Ask Question