Sunday, April 6, 2014

Visual Basic Tutorial : How to Use IF Statement in Visual Basic.Net [Single Line Syntax]

how to use if statement in visual basic.net

In This tutorial I will going to discuss the basic use if "IF Statement" in visual basic programming.

IF statement is one of the powerful statement in visual basic programming, it allows the programmer to make a condition whether the system or program do an action.

This is the correct syntax on how to use this statement..

Note: Before you write this code, remove the [] to avoid program crash or errors.
If condition [ Then ] [ statements ][ ElseIf elseifcondition [ Then ] [ elseifstatements ] ][ Else [ elsestatements ] ]End If
' Single-line syntax:If condition Then[ statements ] [ Else [ elsestatements ] ]

According to support.microsoft.com it Conditionally executes a group of statements, depending on the value of an expression.


Credits to mdsn.microsoft.com



condition
Required. Expression. Must evaluate to True or False, or to a data type that is implicitly convertible toBoolean.
If the expression is a Nullable Boolean variable that evaluates to Nothing, the condition is treated as if the expression is not True, and the Else block is executed.
Then
Required in the single-line syntax; optional in the multiple-line syntax.
statements
Optional. One or more statements following If...Then that are executed if condition evaluates to True.
elseifcondition
Required if ElseIf is present. Expression. Must evaluate to True or False, or to a data type that is implicitly convertible to Boolean.
elseifstatements
Optional. One or more statements following ElseIf...Then that are executed if elseifcondition evaluates toTrue.
elsestatements
Optional. One or more statements that are executed if no previous condition or elseifcondition expression evaluates to True.
End If
Terminates the If...Then...Else block.

The IF Statement play a valuable role in visual basic.net programming, with the use of this statement we are able to tell the program to do a specific task for us. 

Watch Video Tutorial





No comments:

Post a Comment