Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A better (and easier) way to create an Wizard based application

Graphical User Interface (GUI)

A better (and easier) way to create an Wizard based application

by  Motor11  Posted    (Edited  )
Using the SSTab control to make a Wizard in VB:

I like to use the SSTab control to make my Wizard-like projects. It's extremely easy to do and, in my mind, is easier to understand than VB6's Wizard project.

So, first we start our new project:
Start a new project (standard EXE)

And add the sstab control to the project:
[color blue]Project -> components
Browse -> tabctrl32 (system32 directory)[/color]

Add a tab control to the form (sstab1)

Change no. of tabs to reflect no. of wizard steps

Add the following to the form_load event:
(this hides the tabs in the tab control so that the user must navigate the project with the next button (ie: Wizard style))

[color green]
Private Sub Form_Load()
SSTab1.TabHeight = 1
SSTab1.TabMaxWidth = 15
SSTab1.Width = Me.Width + 200
SSTab1.Left = -100
SSTab1.Tab = 0
End Sub
[/color]

Add a command button (bottom right of tab)
Name: cmdNext Caption: Next
Make a copy of this button on each tab -as a control array
Double click next button and add the following code:

[color green]
Private Sub cmdNext_Click(Index As Integer)
Dim tab_prepared As Boolean
If prepare_tab(Index + 1) Then
SSTab1.Tab = Index + 1
Debug.Print "User pressed Next " & Str(Index)
Else
Debug.Print "Unable to prepare tab " & Str(Index + 1)
End If
End Sub
[/color]
And, of course, we need the prepare_tab function:
[color green]
Private Function prepare_tab(tab_no As Integer) As Boolean
Select Case tab_no
Case 1
'code to prepare tab number 1
Case 2
'code to prepare tab number 2
End Select
prepare_tab = True

Exit Function
errorhandler:
Debug.Print "Error preparing tab number " & Str(tab_no)
prepare_tab = False
End Function
[/color]

Add a control array of 'back buttons in the same manner but starting on tab number 1 (not zero).
The code for the back button could be:
[color green]
Private Sub cmdBack_Click(Index As Integer)
SSTab1.Tab = Index
End Sub
[/color]

And viola! A wizard that is easy to navigate in the design environment and looks good at run time.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top