Nested If Then Else Structure Visual Basic 6.0 – 11th tutorial

Nested If Then Else Structure

lets take a look at nested if then else structure in visual basic. When we compare condition while staying in a condition comparison or we create a if structure within an if structure is called nested structure. A condition located inside a condition is called nested condition. When programming logics clear first step and again have to execute a condition we can handle it using nested If then else statement.

Every nested statement closes itself inside the parent statement I mean outer statement. And can have its own complete parameters including else too. While in extended statements we use next comparison in else and again next it in next else. its nested because whole next comparison is executed completely staying in its outer statement.

lets see the syntax to get more better understanding.


nested if then else




Write a program to compare numbers of two subjects for a student. If both subjects have marks more then 70 then to show BEST otherwise Bad.

Start a new EXE project and design the form as below:

conditional structure in visual basic

Set all properties of controls as required in project we already have discussed about properties.

Double click to command button to open the code window and type the code as below:

Nested if then else code
conditional structure source coede example

Code understanding:

defining variables

Dim Science As Integer

Dim ComputerScience As Integer

–getting values from text boxes and saving in variables

Science = Text1.Text

ComputerScience = Text2.Text

— outer of nested comparison

If Science >= 70 Then

— inner of nested comparison

If ComputerScience >= 70 Then

MsgBox "Best"


MsgBox "Better"

End If


MsgBox "Bad"

End If

Practice makes the man perfect so keep practicing.

READ  Conditional statements in Visual Basic 6.0 - 8th tutorial

keep visiting our website we will soon update more tutorials and projects. Also we will start learning javascript and HTML soon with latest CSS


Want to read again later ?? Share to save in your social media.