If … Then … ElseIf Structure in Visual Basic 2010

Decision Making Structures:

Decision making structures are very popular in programming languages. They help the program to take certain decisions based on certain conditions. These conditions vary being true or false while you test them. Below you can check how a general format of a decision making structure looks like.

Pic One ElseIf

The main Decision Making Structures used in Visual Basic programming can be:

  1. If Constructions (Simple If, If … Then … Else, If … ElseIf and Nested If)
  2. Select Case Construction
  3. Try … Catch Construction

Simple If Structure:

Simple If Structure or mostly called the If … Then Structure is the most common type of If Structure. It checks only one condition and executes one result based on it. It performs a specific action only when the condition given is true, otherwise the action is skipped away.

General Syntax:

Example Code: (We will check if a given number by the user is positive or not.)


Output 1Output 2









Check Also: [button link=”http://codejow.com/byref-optional-pass-value-vb2010/” size=”default” icon=”fa-paragraph” side=”left” target=”” color=”a3b798″ textcolor=”ffffff”]Pass By Reference & Optional Pass By Value[/button]

If … Then … Else Structure:

This structure acts the same as the simple if structure. Except that it will also generate an output if the condition is false.

General Syntax:

Example Code:


Output 3Output 4









Check Also: [button link=”http://codejow.com/looping-structures-in-visual-basic-2010/” size=”default” icon=”fa-cubes” side=”left” target=”” color=”b79628″ textcolor=”ffffff”]Looping Structures in Visual Basic 2010[/button]

If … ElseIf Structure:

If … ElseIf is the same as the If … Then …. Else structure. But here various conditions are checked and based on the result outputs are generated. You can add as many ElseIf statements as you wish to.

General Syntax:

Code Example: (Grading students based on their percentage)

Note: In the code below, we have also made use of the Logical AND operator to check two conditions at the same time.


Output 5Output 6









Further; you can find articles on Decision Making Structures in Visual Basic 2010 @ CODEJOW

Moreover; feel free to ask your questions, post your comments and enquire about further articles.

Leave a Reply