Wednesday, February 9, 2011

Visual Basic 6.0 - Session 7

A control array is a set of multiple controls of the same type with the same name (often created by using the Copy and Paste command).  You may have encountered this already in adding radio buttons or check boxes to your form.  Individual controls within the array are distinguished by having different Index property values.  So, if you created a control array of option buttons called optChoice, the Click event procedure might look like this:


PrivateSub optChoice_Click(IndexAsInteger)
SelectCase optChoice(Index)
   Case Index=0 Label1.Caption="Monday"
   Case Index=1 Label1.Caption="Tuesday"
   Case Index=2 Label1.Caption="Wednesday"
   Case Index=3 Label1.Caption="Thursday"
   Case Index=4 Label1.Caption="Friday"
   Case Index=5 Label1.Caption="Saturday"
   CaseElse Label1.Caption="Sunday"
EndSelect
EndSub

The code above would change the label caption as each different option button was selected.  Try this out, then add code to change the label background colour (to something appropriate) for each different day.  Link to the menu Multiway Selection heading in the main form menu under the heading Colour My Days.

Before we continue with the last structures — iterations — check that the menu headings on Main are all correct and linked (by code) to the correct forms.  Check the list below and change any that need to be changed. 
 
Menu
Quit
Introduction (Sequences)
    Example 1 (– Welcome to VB)  from Session 1
    Example 2 (– Colour changer)  from Session 2
Message and Input boxes
    Sequence (– Computer Conversation)  from Session 3
Selection
    Binary (- The calculator)  from session4
    Binary (- Measurement Converter)  from Session 5
    Multiway (- Parcel weights) from Session 6
    Multiway (- Noise levels)  from Session 6
    Multiway (-Colour my days) from Session 7
Iteration

Iterations
Iterations or loops are structures that allow a statement or group of statements to be carried out repeatedly while some condition remains true (or for a counted number of times).   Each iteration MUST contain a way of stopping the looping.  There are 2 basic iteration structures:
•  Pre-test iterations: in these loops, the condition to be met occurs at the beginning of the loop and the code will not run at all if the condition is never met
.  •  Post-test iterations: in these loops, the condition to be met is at the end of the loop so that the code always runs as least one

No comments:

Post a Comment