Visual Basic If Statement - Tutlane
Có thể bạn quan tâm
In Visual Basic, If statement is useful to execute the block of code or statements conditionally based on the value of an expression.
Generally, in Visual Basic, the statement that needs to be executed based on the condition is known as a “Conditional Statement” and the statement is more likely a block of code.
Syntax of Visual Basic if Statement
Following is the syntax of defining the if statement in Visual Basic programming language.
If bool_expression Then // Statements to Execute if condition is true End If
If you observe the above If statement syntax, the statements inside of the If condition will be executed only when the “bool_expression” returns true otherwise, those statements will be ignored for execution.
Following is the sample example of using the If statement in Visual Basic programming language.
Dim x As Integer = 20 If x >= 10 Then Console.WriteLine("Number Greater than 10") End If
If you observe the above example, the Console statement will be executed only when the defined condition (x >= 10) returns true.
Visual Basic If Statement Flow Chart Diagram
Following is the flow chart diagram, which will represent the process flow of the If statement in Visual Basic programming language.

If you observe the above Visual Basic If statement flow chart diagram, when the defined condition is true, the statements within the If condition will be executed; otherwise, the If condition will end without executing the statements.
Visual Basic If Statement Example
Following is the example of defining the If statement in Visual Basic programming language to execute the block of code or statements based on a Boolean expression.
Module Module1 Sub Main() Dim x As Integer = 20, y As Integer = 10 If x >= 10 Then Console.WriteLine("x is Greater than 10") End If If y <= 5 Then Console.WriteLine("y is less than or equals to 5") End If Console.WriteLine("Press Enter Key to Exit..") Console.ReadLine() End Sub End Module
If you observe the above example, we defined two If conditions to execute the statements based on the defined variables (x, y) values.
When we execute the above Visual Basic program, we will get the result as shown below.
If you observe the above result, only one If condition is true that’s the reason only one statement printed on the console window.
This is how we can use the If statement in Visual Basic programming language to execute the block of code or statements based on our requirements.
Từ khóa » Visual Basic If
-
If...Then...Else Statement - Visual Basic - Microsoft Docs
-
#If...Then...#Else Directives - Visual Basic | Microsoft Docs
-
Lệnh If Else Trong Visual Basic: Dùng để Rẻ Nhánh Chương Trình
-
VB.Net - If...Then...Else Statement - Tutorialspoint
-
Visual Basic If-Else-If Statement - Tutlane
-
Hướng Dẫn Cách Viết Cấu Trúc IF THEN ELSE Trong VBA Excel
-
HƯỚNG DẪN ĐẦY ĐỦ CÂU LỆNH IF TRONG VBA - Học Excel Online
-
Visual Basic If Statement - The Coding Guys
-
Visual Basic 6 Tutorial => If / Else Statement
-
Mệnh đề If-else Trong VBA - VietTuts
-
MS Excel: How To Use The IF-THEN-ELSE Statement (VBA)
-
VB.NET If Then, ElseIf, Else Examples
-
If Then Else Statement - VB.NET
-
How To Use The IF Keyword In Visual Basic - Unaura