Professional Excel Development [Electronic resources] : The Definitive Guide to Developing Applications Using Microsoft® Excel and VBA® نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Professional Excel Development [Electronic resources] : The Definitive Guide to Developing Applications Using Microsoft® Excel and VBA® - نسخه متنی

Stephen Bullen, Rob Bovey, John Green

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











Wizards


Wizard dialogs are normally used when we need to collect a reasonably large amount of data from the user. The only absolute requirement this data must fulfill in order to be a candidate for a wizard dialog is that the bits of data being collected must be logically related to each other in some way. Wizard dialogs are particularly useful where the data being collected has the following characteristics in addition to being logically related:

The information is complex and varied.

The information must be supplied in a defined order because earlier selections alter the allowable parameters of later selections.

The user does not need to understand the relationship between earlier and later choices. The wizard dialog can then abstract this decision-making process away from the user.


The primary purpose of a wizard dialog is to reduce the number of choices the user must make at any one time to a manageable level. An important secondary purpose of a wizard dialog is to allow us to alter the parts of the user interface that depend on the selections the user is currently making without having to do so in a way that is visible to the user and thereby potentially distract them from the task at hand (see Dynamic Userforms later for an example).

Design Rules for Wizard Dialogs


The first page of a wizard dialog should explain the purpose of the wizard and the steps involved, but always have a "Don't show me this again" check box to automatically skip the first page if the user wants.

The last page of a wizard dialog should confirm everything the user has entered and all the choices made, and no actions are performed until the user clicks the Finish button.

Always display the step number within the wizard that the user is currently working on as well as the total number of steps left to complete. This information is typically displayed in the title bar, although we've seen perfectly acceptable designs that display it elsewhere.

Navigation through the wizard is typically controlled by a series of four buttons: Cancel, Back, Next and Finish. The enabled state of these buttons should be used to provide visual clues to the user about how they're doing. Track the user's progress through the wizard and watch their input during each step of the wizard. Based on where the user is and what data he has entered, enable only the navigation buttons that makes sense, such as the following:Validation earlier).

Last step with all data entered and validatedCancel enabled, Back enabled, Next disabled and Finish enabled.

The user has completed all wizard steps correctly but then used the Back button to revisit an earlier stepAll buttons enabled until the user makes an entry that invalidates the ability of the wizard to finish or move forward.

In, say, a five-step wizard, if steps four and five allow the user to enter optional information, the Finish button can be enabled after step three. Excel's Chart Wizard is a good example of this.

The user can move back and forth through wizards to his heart's content. Therefore, you must always keep track of the status of all steps in the wizard in order to properly set the status of the navigation buttons. It is perfectly appropriate for the user to click Finish from step two of a five-step wizard as long as he has completed all five steps and has just moved back to step two in order to make a minor change.

In some wizard designs, selections made on a step affect other selections on that same step. If a selection on a step makes another selection on that same step unnecessary, do not hide the controls for the unnecessary selection. Just disable them. Controls that pop in and out of existence in front of the user's face tend to be a confusing distraction.

Creating a Wizard Dialog


The easiest way to create a wizard dialog is to use a MultiPage control, with each page of the control being used for a separate step of the wizard and a common set of buttons at the bottom. Figure 10-8 shows the wizard userform template included on the CD in the WizardDemo.xls workbook, with the MultiPage tabs showing on the right side. Prior to distributing the wizard, the MultiPage should be formatted to not have any tabs showing by setting its Style property to fmTabStyleNone, and reducing both the MultiPage's and userform's width accordingly.

Figure 10-8. An Empty Wizard Userform Using a MultiPage Control for the Steps

Unfortunately, the MultiPage control is not without its problems, particularly when using non-MSForms controls within a page. If you intend to use the RefEdit control or any of the Windows Common Controls (such as the TreeView and ListView control), you should use a separate Frame control for each step of the wizard instead of a MultiPage control. If using a Frame control, it's easiest to develop the wizard with all the frames visible at the same time, on a userform much larger than the final version. When the wizard is complete, change the frames' left and top so they all overlap and reduce the userform to its correct size.

Listing 10-18 shows the code for the four navigation buttons, which each call further procedures to initialize and validate the controls in each step. The content of the InitializeStep and bValidateStep procedures will obviously depend on the contents of the step, so have not been shown here. As well as initializing the controls on each page, the InitializeStep procedure should update the userform's caption to show the step number and enable/disable the navigation buttons.

Listing 10-18. The Navigation Code for a Wizard Dialog



Private Sub cmdCancel_Click()
mbUserCancel = True
Me.Hide
End Sub
Private Sub cmdBack_Click()
' Can't go back from step 1.
If mlStep > 1 Then
' No validation is required when moving back.
mlStep = mlStep - 1
mpgWizard.Value = mlStep - 1
InitializeStep mlStep
End If
End Sub
Private Sub cmdNext_Click()
' Can't go forward from the last step.
If mlStep <= mlNumSteps Then
' We validate the controls on the current step
' before allowing the user to move forward.
If bValidateStep(mlStep) Then ' Validation succeeded.
mlStep = mlStep + 1
mpgWizard.Value = mlStep - 1
InitializeStep mlStep
Else ' Validation failed.
MsgBox gsErrMsg, vbCritical, gsAPP_TITLE
gsErrMsg = gsEMPTY_STRING
End If
End If
End Sub
Private Sub cmdFinish_Click()
' The last step must be validated before the user
' is allowed to complete the wizard.
If bValidateStep(mlStep) Then ' Validation succeeded.
mbUserCancel = False
Me.Hide
Else ' Validation failed.
MsgBox gsErrMsg, vbCritical, gsAPP_TITLE
gsErrMsg = gsEMPTY_STRING
End If
End Sub


/ 225