Link to home
Start Free TrialLog in
Avatar of skhan22
skhan22

asked on

Progressbar to track process

I wrote this procedure that performs multiple functions. After the user selects his/her name from a list box and clicks the command button on the form, the process verifies user authentication, move file from media into user's directory, rename files and some other things. i would like to show the progress of this whole process in a progressbar displayed in a statusbar.
Thanks in advance
sk
Avatar of MUPPET
MUPPET

add the componant microsoft comman controls, place componant on form.

progressbar1.min = 0
progressbar1.max = 100

progressbar1.value = 10

your events

progressbar1.value = 20

etc
ASKER CERTIFIED SOLUTION
Avatar of sanjaykattimani
sanjaykattimani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you know how many process are in place you could use this simple process that I use for my applications.  You should modify it for your own use as this is a "training" application for progress bars only.  Also, set your max to the number of processes you are having to perform.  I also use three functions (not shown below) call ProgressBar_START(min,max,statusMessage), ProgressBar_Increment(newStatusMessage), and ProgressBar_END() that basically bring the progress bar to visible status, sets the min/max values, increments the progress bar as you work on predefined process, then makes the control (and possibly additional controls like what you are doing now labels) invisible.  

Lot's of options, but hopefully below will at least get you started with how to use a ProgressBar control.  Don't forget to reference the Common Controls Dialog to see the Progress Bar on the ToolBox.

Dan M.
dmstrat@yahoo.com

------------------------------------------------------


VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmProgressBar
   Caption         =   "Progress Bar Training"
   ClientHeight    =   3390
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7395
   LinkTopic       =   "Form1"
   ScaleHeight     =   3390
   ScaleWidth      =   7395
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer Timer2
      Left            =   5400
      Top             =   0
   End
   Begin VB.TextBox Text3
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   5640
      TabIndex        =   5
      Text            =   "100"
      Top             =   2040
      Width           =   735
   End
   Begin VB.TextBox Text2
      Height          =   285
      Left            =   1200
      TabIndex        =   4
      Text            =   "0"
      Top             =   2040
      Width           =   855
   End
   Begin VB.TextBox Text1
      Height          =   285
      Left            =   3240
      TabIndex        =   2
      Text            =   "100"
      Top             =   120
      Width           =   1095
   End
   Begin MSComctlLib.ProgressBar ProgressBar1
      Height          =   735
      Left            =   1200
      TabIndex        =   1
      Top             =   1080
      Visible         =   0   'False
      Width           =   5175
      _ExtentX        =   9128
      _ExtentY        =   1296
      _Version        =   393216
      Appearance      =   1
   End
   Begin VB.CommandButton Command1
      Caption         =   "Run Progress Bar"
      Height          =   615
      Left            =   2880
      TabIndex        =   0
      Top             =   2400
      Width           =   1815
   End
   Begin VB.Label LabelTest
      Height          =   255
      Left            =   3240
      TabIndex        =   9
      Top             =   1800
      Width           =   975
   End
   Begin VB.Label LabelThing
      BorderStyle     =   1  'Fixed Single
      Height          =   495
      Left            =   6120
      TabIndex        =   8
      Top             =   0
      Width           =   1215
   End
   Begin VB.Label Label3
      Alignment       =   1  'Right Justify
      Caption         =   "Max"
      Height          =   255
      Left            =   4800
      TabIndex        =   7
      Top             =   2055
      Width           =   735
   End
   Begin VB.Label Label2
      Caption         =   "Min"
      Height          =   255
      Left            =   2160
      TabIndex        =   6
      Top             =   2055
      Width           =   855
   End
   Begin VB.Label Label1
      Alignment       =   2  'Center
      Caption         =   "Speed Interval in microseconds (1000 = 1 sec)"
      Height          =   495
      Left            =   2760
      TabIndex        =   3
      Top             =   480
      Width           =   2055
   End
End
Attribute VB_Name = "frmProgressBar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim intMin, intMax, intTimerInterval As Integer
Dim intDiff, intPosition As Integer
Dim blnCheck, blnEnable As Boolean

Private Sub Form_Load()
    blnCheck = False
    blnEnable = False
    Timer2.Interval = 100   ' Set Timer interval.
End Sub


Private Sub Timer2_Timer()
    LabelThing.Caption = Time   ' Update time display.
    LabelTest.Caption = "counter:" & intPosition
    If intPosition = intMax Then
      Timer2.Enabled = False
      intPosition = intMin
      ' hide progressbar
      ProgressBar1.Visible = False
      Exit Sub
    Else
      intPosition = intPosition + 1
      ProgressBar1.Value = intPosition
    End If
   
End Sub

Private Sub Command1_Click()
'assume the following variables can not be changed:
'---------------------------
intTimerInterval = CDec(Text1.Text)
intMin = CInt(Text2.Text)
intMax = CInt(Text3.Text)
'MsgBox "Min:" & intMin & "Max:" & intMax & "Interval:" & intTimerInterval

If intMax > intMin Then
    ProgressBar1.Max = intMax
    ProgressBar1.Min = intMin
    ProgressBar1.Visible = True
    intDiff = intMax - intMin
    intPosition = intMin
    ProgressBar1.Value = intPosition
    Timer2.Interval = Text1.Text 'intTimeInterval
    'Timer2.Interval = 100 ' intTimeInterval
    blnEnable = True
Else
    MsgBox "need max to be bigger than the min"
    blnEnable = False
End If
Timer2.Enabled = blnEnable
End Sub
=======================EOF==============================
Avatar of skhan22

ASKER

Thank you all of you for your suggestions and taking some timeout to answer my question.
thanks
sk