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
 
 
 
 
 
TitleUse a ProgressBar with a long task without timer
Keywordsprogress bar, ProgressBar, long task, status
CategoriesSoftware Engineering, Controls
 
When beginning a long task, make the ProgressBar visible. Set its Min and Max properties to represent the task and perform the task. The task periodically updates the ProgressBar.
 
Private Sub cmdPerformTask_Click()
Dim i As Integer
Dim j As Long

    ' Don't let the user click this till we
    ' are done with this task.
    cmdPerformTask.Enabled = False
    MousePointer = vbHourglass
    DoEvents

    ' Start the progress bar at zero.
    pbTaskProgress.Value = pbTaskProgress.Min
    pbTaskProgress.Visible = True
    DoEvents

    ' Perform the long task.
    For i = 1 To 100
        ' Do something long.
        For j = 1 To 500000
        Next j

        ' Increase the ProgressBar's value.
        pbTaskProgress.Value = i
    Next i

    ' Reenable the button.
    pbTaskProgress.Visible = False
    cmdPerformTask.Enabled = True
    MousePointer = vbDefault
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated