by Dinesh Thakur Category: Decisions and Conditions

An application needs a built-in capability to test conditions and take a different course of action depending on the outcome of the test. Visual Basic provides three control flow, or decision, structures :

 

If……Then : The If….Then structure tests the condition specified, and if it’s True, executes the statement(s) that follow. The If structure can have a single-line or a multiple-line syntax.

 

The general form is : If condition Then statement

 

If……Then……Else : A variation of the If……Then statement is the If……Then……Else statement, which executes one block of statements if the condition is True and another if the condition is False. The syntax of the If… Then….Else statement is as follows:

 

If condition Then

statement block-1

Else

statement block-2

End If

 

Select Case : The Select Case structure compares one expression to different values. The advantage of the Select Case statement over multiple If…..Then…..Else statements is that it makes the code easier to read and maintain.

 

The Select Case structure tests a single expression, which is evaluated once at the top of the structure. The result of the test is then compared with several values, and if it matches one of them, the corresponding block of statements is executed.

 

The syntax is :

Select Case expression

Case value1

Statement block-1

Case value2

Statement block-2

.

.

.

Case Else

Statement block

End Select

 



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.