How many message boxes are displayed after running each sub-procedure below? Opt
ID: 3641276 • Letter: H
Question
How many message boxes are displayed after running each sub-procedure below?Option Explicit
Sub A()
Dim lngA As Long
For lngA = 1 To 3 Step 3
MsgBox "Hello"
Next
End Sub
Sub B()
Dim lngA As Long
For lngA = 1 To 3 Step 2
MsgBox "Hello"
Exit For
Next
End Sub
Sub C()
Dim lngA As Long
For lngA = 1 To 3 Step 1
MsgBox "Hello"
Next
End Sub
Answer
1 from Sub A
1 from Sub B
1 from Sub C
1 from Sub A
2 from Sub B
1 from Sub C
1 from Sub A
1 from Sub B
3 from Sub C
2 from Sub A
2 from Sub B
3 from Sub C
3 from Sub A
1 from Sub B
3 from Sub C
3 from Sub A
3 from Sub B
3 from Sub C
Explanation / Answer
For Sub A() the for loop starts lngA at 1 a message box is displayed lngA is incremented to 4 the for loop ends the subroutine ends For Sub B() the for loop starts lngB at 1 a message box is displayed the exit for command breaks out of the for loop the subroutine ends For Sub C() the for loop starts lngC at 1 a message box is displayed the for loop increments lngC to 2 a message box is displayed the for loop increments lngC to 3 a message box is displayed the for loop increments lngC to 4 the for loop ends the subroutine ends After running all subroutines, the message boxes displayed are: 1 from Sub A 1 from Sub B 3 from Sub C
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.