Programming dependencies in a wizard

In most wizards, a user's response on a particular step can affect what's displayed in a subsequent step. In the CD-ROM example, the user indicates which products he or she uses in Step 3 and then rates those products in Step 4. The OptionButtons for a product's rating are visible only if the user has indicated a particular product.

Programmatically, this is accomplished by monitoring the MultiPage's Change event. Whenever the value of the MultiPage is changed (by clicking the Back or Next button), the MultiPage1_Change procedure is executed. If the MultiPage control is on the last tab (Step 4), the procedure examines the values of the CheckBox controls in Step 3 and makes the appropriate adjustments in Step 4.

In this example, the code uses two arrays of controls — one for the product CheckBox controls (Step 3) and one for the Frame controls (Step 4). The code uses a For-Next loop to hide the Frames for the products that are not used and then adjusts their vertical positioning. If none of the check boxes in Step 3 are checked, everything in Step 4 is hidden except a TextBox that displays Click Finish to exit (if a name is entered in Step 1) or A name is required in Step 1 (if a name is not entered in Step 1). The MultiPage1_Change procedure is shown in Listing 15-2.

Listing 15-2: Bringing Up the Page Corresponding to the User's Choice

Private Sub MultiPage1_Change() ' Set up the Ratings page?

If MultiPage1.Value = 3 Then

Create an array of CheckBox controls Dim ProdCB(1 To 3) As MSForms.CheckBox Set ProdCB(1) = cbExcel Set ProdCB(2) = cbWord Set ProdCB(3) = cbAccess

Create an array of Frame controls

Dim ProdFrame(1 To 3) As MSForms.Frame

Set ProdFrame(l) = FrameExcel

Set ProdFrame(2) = FrameWord

Set ProdFrame(3) = FrameAccess

TopPos = 22 FSpace = 8 AtLeastOne = False

Loop through all products For i = l To 3

If ProdCB(i) Then

ProdFrame(i).Visible = True ProdFrame(i).Top = TopPos

TopPos = TopPos + ProdFrame(i).Height + FSpace AtLeastOne = True

Else

ProdFrame(i).Visible = False End If Next i

' Uses no products?

If AtLeastOne Then lblHeadings.Visible = True Image4.Visible = True lblFinishMsg.Visible = False

Else lblHeadings.Visible = False Image4.Visible = False lblFinishMsg.Visible = True If tbName = "" Then lblFinishMsg.Caption = _

"A name is required in Step l."

Else lblFinishMsg.Caption = _ "Click Finish to exit."

End If End If End If End Sub

0 0

Post a comment