0% found this document useful (0 votes)
163 views3 pages

Control Structures in Visual Basic 6

Visual Basic 6.0 supports various control structures for controlling program flow, including if-then, if-then-else, nested if-then-else, and select case structures. If-then performs an action if a condition is true, while if-then-else allows specifying different actions for true or false conditions. Nested if-then-else structures test for multiple cases by placing if statements inside other if statements. Select case provides an alternative to nested if-then-else for selectively executing code from multiple blocks based on a single index value.

Uploaded by

Rohit Jagtap
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
163 views3 pages

Control Structures in Visual Basic 6

Visual Basic 6.0 supports various control structures for controlling program flow, including if-then, if-then-else, nested if-then-else, and select case structures. If-then performs an action if a condition is true, while if-then-else allows specifying different actions for true or false conditions. Nested if-then-else structures test for multiple cases by placing if statements inside other if statements. Select case provides an alternative to nested if-then-else for selectively executing code from multiple blocks based on a single index value.

Uploaded by

Rohit Jagtap
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Control Structures in Visual Basic 6.

0
Control Statements are used to control the flow of program's execution. Visual Basic supports
control structures such as if... Then, if...Then ...Else, Select...Case, and Loop structures such as
Do While...Loop, While...Wend, For...Next etc method.

If...Then selection structure


The If...Then selection structure performs an indicated action only when the condition is True;
otherwise the action is skipped.
Syntax of the If...Then selection
If <condition> Then
statement
End If
e.g.: If average>75 Then
txtGrade.Text = "A"
End If

If...Then...Else selection structure


The If...Then...Else selection structure allows the programmer to specify that a different action is
to be performed when the condition is True than when the condition is False.
Syntax of the If...Then...Else selection
If <condition > Then
statements
Else
statements
End If
e.g.: If average>50 Then
txtGrade.Text = "Pass"
Else
txtGrade.Text = "Fail"
End If

Nested If...Then...Else selection structure

Nested If...Then...Else selection structures test for multiple cases by placing If...Then...Else
selection structures inside If...Then...Else structures.
Syntax of the Nested If...Then...Else selection structure
You can use Nested If either of the methods as shown above
Method 1
If < condition 1 > Then
statements
ElseIf < condition 2 > Then
statements
ElseIf < condition 3 > Then
statements
Else
Statements
End If
Method 2
If < condition 1 > Then
statements
Else
If < condition 2 > Then
statements
Else
If < condition 3 > Then
statements
Else
Statements
End If
End If
EndIf
e.g.: Assume you have to find the grade using nested if and display in a text box
If average > 75 Then
txtGrade.Text = "A"
ElseIf average > 65 Then
txtGrade.Text = "B"
ElseIf average > 55 Then
txtGrade.text = "C"
ElseIf average > 45 Then
txtGrade.Text = "S"
Else

txtGrade.Text = "F"
End If

Select...Case selection structure


Select...Case structure is an alternative to If...Then...ElseIf for selectively executing a single
block of statements from among multiple block of statements. Select...case is more convenient to
use than the If...Else...End If. The following program block illustrate the working of
Select...Case.
Syntax of the Select...Case selection structure
Select Case Index
Case 0
Statements
Case 1
Statements
End Select
e.g.: Assume you have to find the grade using select...case and display in the text box
Dim average as Integer
average = txtAverage.Text
Select Case average
Case 100 To 75
txtGrade.Text ="A"
Case 74 To 65
txtGrade.Text ="B"
Case 64 To 55
txtGrade.Text ="C"
Case 54 To 45
txtGrade.Text ="S"
Case 44 To 0
txtGrade.Text ="F"
Case Else
MsgBox "Invalid average marks"
End Select
Note: In this example I have used a message box function. In later lessons you will learn how to
use message box functions.

You might also like