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
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