Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay a status bar showing the steps in a long task
DescriptionThis example shows how to display a status bar showing the steps in a long task in Visual Basic 6.
KeywordsStatusBar, steps, stages, progress, ProgressBar
CategoriesControls, Software Engineering
 
When the program starts, it prepares the StatusBar. It creates panels to show a message, a progress bar, and the time.

A key step here is calling subroutine MoveIntoStatusBar, which reparents the ProgressBar control into the StatusBar.

 
Private Sub Form_Load()
    StatusBar1.Panels.Clear

    With StatusBar1.Panels.Add()
        .Text = ""
    End With

    With StatusBar1.Panels.Add()
        .Width = 2 * 1440
    End With
    MoveIntoStatusBar StatusBar1, ProgressBar1, 2

    With StatusBar1.Panels.Add()
        .Style = sbrTime
        .AutoSize = sbrSpring
    End With
End Sub

Public Sub MoveIntoStatusBar(ByVal sbr As StatusBar, ByVal _
    ctl As Control, ByVal panel_number As Long)
Dim r As RECT

    ' Reparent the control into the status bar.
    SetParent ctl.hWnd, sbr.hWnd

    ' Get the status bar's panel's rectangle.
    SendMessage sbr.hWnd, SB_GETRECT, panel_number - 1, r

    ' Position the control in the panel.
    MoveWindow ctl.hWnd, r.Left, r.Top, r.Right - r.Left, _
        r.Bottom - r.Top, True
End Sub
 
When you click the Go button, the program sets the ProgressBar's minimum and maximum values. Then for a series of steps, the program calls subroutine SetProgress to show the current state of progress, and then wastes a little time.

Subroutine SetProgress displays a text message and sets the ProgressBar's value.

 
Private Sub cmdGo_Click()
    ProgressBar1.Min = 0
    ProgressBar1.Max = 7

    SetProgress "Step 1 of 4", 1
    WasteTime 0.5
    SetProgress "Step 1 of 4", 2
    WasteTime 0.5

    SetProgress "Step 2 of 4", 3
    WasteTime 0.5

    SetProgress "Step 3 of 4", 4
    WasteTime 0.5

    SetProgress "Step 4 of 4", 5
    WasteTime 0.5
    SetProgress "Step 4 of 4", 6
    WasteTime 0.5

    SetProgress "Done", 0
End Sub

Private Sub SetProgress(ByVal txt As String, ByVal _
    progress_value As Integer)
    StatusBar1.Panels(1).Text = txt
    StatusBar1.Refresh

    ProgressBar1.Value = progress_value
    ProgressBar1.Refresh
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated