Tutorial 5
- The Repetition
Structure – Iteration Construct(Looping)
- Repeat one or more
program instructions either a specified number or time or until some
condition is met
- Three types of
iteration constructs in Visual Basic
- For Next Loop –
automatic loop counter
- For counter =
startvalue to endvalue {step stepvalue}
- Next Counter
- Startvalue –
where to start
- Stopvalue – where
to stop
- Stepvalue amount
to increment or decrement counter each time
- If not stepvalue
default 1
- Startvalue,
endvalue, stepvalue must be numeric
- If stepvalue is
positive than endvalue must be greater than or equal endvalue
- If stepvalue is
negative endvalue must be less than or equal startvalue
- Steps
- Loop initializes
the counter to the startvalue at the beginning of the loop
- If stepvalue is
positive, the loop checks if the value in the counter is greater than
endvalue ( if stepvalue is negative, the loop checks if value of the
counter is less than endvalue) The loop stops if the condition is
met, if not go to step 3
- The loop adds
the stepvalue to the counter and repeats 1,2
- Do While
- Do While
<condition>
- Loop
- Executes 0 or
more times
- Pretest loop
- Performs body of
loop while condition is true
- Some statement in
loop must cause the condition to go false or else endless loop
- Do Until
- Do
- Loop until
<condition>
- Executes 1 or
more times
- Posttest loop
- Performs body of
loop while condition is false(stops when condition true)
- Some statement in
loop must cause the condition to go true or else endless loop
- Counter
- Numeric variable
used for counting something
- Accumulator
- Used for
accumulating(adding together) something
- Initializing
- Assign a beginning
value to the counter or accumulator
- Incrementing
- Adding to a the
value stored in the counter or accumulator
- Control array
- Group of controls
that perform same task
- Each control has
same name
- Each control has a
unique index
- Reflects controls
position within the array
- Refer to a control
by name(index)
- First control just
name
- Other controls
name(index)
- Index # 1 to ?
- .example
- chkboxes
- chkboxes(1)
- chkboxes(2)
- Create control
array
- Copy and paste
- If control already
on form
- Select a control
and change name property to name of control array, do this for each
control in array
- All controls
share the same method
- ChDone_Click(Index
as Integer)
- Events
- Change event
- Occurs when contents
of the text box are changed
- UnLoad
- Occurs when a form
is about to be removed from the screen
- Pressing close box
- Or programmer calls Unload method