PART A: SYNTAX OF REPETITION STRUCTURES Do…Loop (Condition controlled with a 1.

advertisement
PART A: SYNTAX OF REPETITION
STRUCTURES
1.
Do…Loop (Condition controlled with a
condition at the beginning of the loop)
Do While | Until [condition]
[statements]
Exit Do
[statements]
Loop
2.
Do…Loop (Condition controlled with a
condition at the end of the loop)
4.
What does ScaleMode property allow to do?
5.
Name the measurement units available in
Visual Basic. What is the default measuring system of
the form
in Visual Basic?
6.
How much of an inch is a twip?
7.
What co-ordinates does the top left corner of
the form have? In what direction the x position and y
position
change?
8.
What is the position of the bottom left corner?
Top right corner? Bottom right corner?
9.
Move the image imgWorld 1000 twips to the
right and 500 twips to the bottom (use two ways).
10.
Place the picture called picMy in the top left
corner and make it travel to the top right corner.
Do
[statements]
Exit Do
[statements]
Loop While | Until [condition]
3.
For…Next Loop (Counter controlled)
For Index = Start To End Step step
[statements]
Exit For
[statements]
Next Index
4.
While…When Loop (Condition controlled)
While [condition]
[statements]
Wend
5.
Timer event (Time controlled loops)
Private Sub tmrEventName_Timer()
[statements]
End Sub
PART B: QUESTIONS
1.
Give real-life examples of counter controlled
loops, condition controlled loops and time controlled
loops.
2.
Identify the following repetition types: go to
school every day, practice until you master the song,
repeat
the medicine dose 5 times.
3.
What are infinite loops? How can infinite
loops be avoided? How can one terminate an infinite
loop?
(Ctrl+Break)
11.
What is the purpose of a timer controlled
loop? What prefix is used before the name of such an
event?
12.
Name the main properties of a timer event and
state what settings they can get.
13.
What should be done to pause a timer event?
What happens when the timer’s Enabled property is
set to
False? When can the timer’s Interval property
be set?
14.
What happens when you place too many
timers on the form?
15.
In a timer event (after placing a timer on the
form) move the imgFace 25 twips to the right every 5
seconds.
16.
What is the purpose of placing a condition at
the beginning of the Do…Loop? At the end?
17.
State the difference between While and Until
in the Do..Loop.
18.
When will a Do..Loop stop running?
19.
Using the While..Wend loop sum up all the
positive integers until the sum reaches 1000 or over.
20.
If you invest 1000 at 5% for 5 years, how
much money will you have at the end of the 5th year?
21.
Write a program to add numbers 100 to 500
(use an accumulator called sum to store the changing
value in
it).
22.
Sum the odd numbers from 51 to 100.
23.
Sum numbers from 50 to 30.
24.
Compute the factorial of 5!
25
How many different kinds of looping
statements does Visual Basic support?
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
How many different Do statements does Visual Basic support?
True or false: A block can consist of a single statement.
How can you utilize a loop for correcting user errors?
What Step value does Visual Basic assume if you don't specify any Step value?
Which statement, the Do or For statement, supports a loop that continues for a specified number of times?
Which statement, the Do or For statement, supports a loop that continues according a relational test?
What is the difference between a Do While and a Do Until loop?
What is the difference between a Do While and a Do-Loop While loop?
What is an iteration?
How can you force a For loop to count down rather than up?
If a For loop's initial starting value is greater than the ending value, what must be true for the increment
value?
What statements terminate Do and For loops early?
RGB (r, g, b) and QBColor(c) functions. How can colours be changed to display their full range. Use
For…Next loops. In case of RGB function use nested For..Next loops.
Generate randomly three different numbers. The first one between 0 and 10, the second one
between 10 and 49, the third one between 50 and 100. Make the numbers become different every time you
run a cmdRandom click event.
Draw a red pixel in the middle of the form, a blue line from the top left corner to the middle of the form,
a green box anywhere at the bottom of the form, a black circle close to the top right corner, an ellipse close
to the bottom right corner, an arc in the same place..
What would you do to make your pixel travel randomly on the form? Write a short program to accomplish
this. Do not allow the pixel to leave the form.
Review the repetition programs we did in class (odd numbers, factorial, inheritance, allowance, bouncing
picture).
3
PART C: TRACING OF VISUAL BASIC CODE
1.
When will the following loop be terminated?
Private Sub cmdButton_Click()
Dim Num As Single
Num = 7
Do While Num <> 0
Num = Num – 2
Loop
End Sub
2.
event
7.
How many times does the following loop
execute?
What would be the outcome of the following
Private Sub tmrMove_Timer()
tmrMove.Interval = 1000
picMy.Left = picMy.Left +100
End Sub
Dim I As Integer
For I = 1 To 10
Beep
Next I
Write Code That...
1.
Write a program that assigns the value of 34
to a variable and then asks the user to guess
the number using
an input box. Use a Do loop to check the
user's guess and keep asking for additional guesses
until the user
guesses the number.
Find the Bug
1.
3.
Trace the program and
Private Sum cmdCalculation_Click()
Dim Amount As Integer, Ctr As
Larry, a fledgling programmer, wrote the
following For loop that seems to be in an
infinite loop. Can you
spot the problem?
Integer
4.
execute?
For i = 1 To 25
Total = Total * I
i=i-1
Next i
Amount = 175
Ctr =
How many times does the following loop
2.
Dim I As Integer
I = 10
Do While I > 1
I=I-1
Loop
5.
How many times does the following loop
execute?
Dim I As Integer
I = 10
Do While I >= 1
I=I-1
Loop
6.
How many times does the following loop
execute?
Dim I As Integer
I = 10
Do Until I > 1
I=I-1
Loop
Kim wants her For loop to loop for 100
iterations but she's having trouble. Tell Kim
what's wrong with the
following attempt: For I = 100 To 1 Step 1
Extra Credit
A nested loop is a loop within a loop. The outer loop
determines how many times the inner loop executes.
See whether you can determine how many times the
following code beeps the user.
For i = 1 To 5
For j = 1 To 3
Beep
Next j
completes before.
Next i
iterates again.
' The outer loop
' The inner loop
' Inner loop
' Outer loop
Download