Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Conditionals
For exercises 1 to 27, indicate the message box that will be produced. If no message box
is displayed, write “No Message” and if multiple message boxes will be displayed,
indicate them in order. For example, if a message box displaying “apple” would be
followed by a message box displaying “orange” write:
“apple”
“orange”
MsgBox “orange”
MsgBox “pear”
End If
MsgBox “apple”
MsgBox “orange”
Else
MsgBox “pear”
MsgBox “banana”
End If
MsgBox “apple”
End If
MsgBox “orange”
End If
MsgBox “pear”
End If
MsgBox “banana”
MsgBox “kiwi”
End If
End If
Else
If num2*2 = MAXIMUM*2 Then
MsgBox “grapefruit”
Else
MsgBox “lime”
MsgBox “coconut”
End If
End If
25. If MAXIMUM = 25 And num2 <> MAXIMUM Or num1 < num3 Then
MsgBox “apple”
End If
MsgBox “orange”
26. If num3 = 87 Or num2 > num1 And MAXIMUM > LIMIT Then
MsgBox “apple”
End If
MsgBox “orange”
27. If (num3 = 87 Or num2 > num1) And MAXIMUM > LIMIT Then
MsgBox “apple”
MsgBox “orange”
End If
Flowcharting
Exercise Worksheet VBA Programming
In the spaces below, construct a flow chart to represent the control flow of problems 18
and 25 above. You may hand-draw on this sheet or use the Flowcharting shapes of
Microsoft Word.
Problem 18
Problem 25
Exercise Worksheet VBA Programming
For exercises 28 to 34, write code segments that will perform the specified action.
Assume that all variables have already been declared and given values.
28. Display a message box that says ‘Hurrah!’ if sum divided by count is
zero.
29. Increment the integer variable total if total is zero and decrement total
otherwise.
30. Display a message box that says ‘num is zero’, ‘num is negative’, or
‘num is positive’ as appropriate based on the current value of num.
Exercise Worksheet VBA Programming
31. Display a message box that says ‘Victory’ only if result is greater than or
equal to 500 and penalty is equal to zero (use nested ifs).
32. Display a message box that says ‘Victory’ only if result is greater than or
equal to 500 and penalty is equal to zero (use logical operators).
33. Assign the smallest of two integer values num1 and num2 to the variable
smallest. (use an if-else statement)
34. Assign the smallest of three integer values num1, num2, and num3 to the
variable smallest.
Loops
For exercises 35 to 49, indicate the message box that will be produced. If no message
box is displayed, write “No Message” and if multiple message boxes will be displayed,
indicate them in order. For example, if a message box displaying “apple” would be
followed by a message box displaying “orange” write:
“apple”
“orange”
Assume the following declarations are in effect at the beginning of each problem: Refer
to Loops in VB .NET - For Loop, While Loop, Do Loop for assistance.
36. Do
If num < MAXIMUM Then Exit Do
num = num + 1
MsgBox num
Loop
37. Do
If num >= MAXIMUM Then Exit Do
num = num + 1
MsgBox num
Loop
38. Do
If num < MIN Then Exit Do
MsgBox num
num = num - 1
Loop
39. Do
If num > MIN Then Exit Do
MsgBox num
num = num - 1
Loop
40. Do
If num > MAXIMUM Then Exit Do
MsgBox num
num = num + 2
Loop
41. Do
If num > MAXIMUM + MIN Then Exit Do
If num - MIN > MIN Then
MsgBox num
End If
Num = num + 1
Loop
42. Do
If num >= MAXIMUM Then Exit Do
num = num + 1
if num*3 > 2*MAXIMUM+num Then
MsgBox num
End If
Loop
43. For value=0 To 7 Step 1
MsgBox value
Next value
Next value
45. . For value=1 To 20 Step 4
MsgBox value
Next value
46. . For value=num To MAXIMUM
MsgBox value
Next value
47. . For value=num To MAXIMUM
If value/4 > 4 Then
MsgBox value
End If
Next value
48. .
Dim outstring As String
outstring = “”
For count1=1 To 3
For count2=1 To 3
Outstring = outstring & “#”
Next count2
MsgBox outstring
Next count1
49. .
For count1=1 To 3
For count2=1 To 3
MsgBox count1*count2
Next count2
Next count1
For exercises 50 to 51, write code segments that will perform the specified action.
Flowcharting
In the spaces below, construct a flow chart to represent the control flow of problems 41
and 48 above. You may hand-draw on this sheet or use the Flowcharting shapes of
Microsoft Word.
Problem 41
Exercise Worksheet VBA Programming
Problem 48