Progressbar Running while a huge procedure is called.

I have a huge procedure which takes about 40 Seconds to complete. I want to show a progressbar looping from 1 to 100
till the procedure is done.
How can I do it?

While huge procedure is running user sees the progress bar running.
Example would be great.

Here is the code which I am trying to run:
Dim Ltime
Ltime = Timer()
  While Timer() - Ltime < 600000000
    Call modHtmlSupport.startHtml
    If i = 100 Then
      i = 1
      i = i + 1
      ProgressBar1.Value = i
    End If
Who is Participating?
VBGuruConnect With a Mentor Commented:
Hope this answers your question

Dim lngMaxLmt As Long
Dim intCount As Integer
Dim intCounter As Integer
Dim lngTime As Long

intCount = 1                                            ' This value ranges from 1 to 30000
intCounter = 1                                          'This value ranges from  1 to 20000 ... So  20000 X 30000 = 600000000
lngMaxLmt = 600000000
ProgressBar1.Min = 1                                    'Set the progress bar range from 1 -- 20000. So every time intCounter value croses 20000 or more then progressbar's value is incremented by 1
ProgressBar1.Max = 20000

Dim Ltime
Ltime = Timer()
lngTime = Timer() - Ltime
While lngTime < 600000000
    Call modHtmlSupport.startHtml                          'Do your processing
    If intCounter >= 20000 Then
      intCounter = 0
      intCount = intCount + 1
      lngTime = 20000 * intCount
      ProgressBar1.Value = intCount
      intCounter = Timer() - Ltime                          'Calucalate the current time
    End If
If ur huge procedure once called, does not return till it ends, there is no good way to find at which point the procedure is at any given point of the time. so showing a progres bar very accuretly will be little hard.

if u can clarify what happense in the procedure sometimes some one might give a better solution
'use a progress bar
'make a standard app and add a picture box called Progress
'in the PublicSub DoProgress..rename the frmSaveApps to your form name
'cut and paste the code and run to see an example
'<<<<<<<  Put this in a bas module  >>>>>>>>
'replace frmTips with the name of your app form
'or name your form frmTips for this example

Option Explicit

'number of things to do ex..files to be backed up
Public intCounted#  
Public Sub DoProgress(Percent)
' Percent is % of graph
Dim Work As Integer
Dim Num As String
Work = Int(Abs(Percent))
If Work > 100 Then Work = 100
With frmSaveTips.Progress       '<<<   With application form
    .BackColor = vbWhite        '<<<   White background
    If Not .AutoRedraw Then     '<<<   picture in memory ?
    .AutoRedraw = True          '<<<   make one
    End If
    .Cls                        '<<<   clear picture in memory
    .ScaleWidth = 100           '<<<   new scalemodus
    .DrawMode = 10              '<<<   not XOR Pen Modus

    Num = Format$(Work, "###") + "% Completed"

    .CurrentX = 50 - .TextWidth(Num) / 2         '<<<  %age is Centered

    .CurrentY = (.ScaleHeight - .TextHeight(Num)) / 2

    frmSaveTips.Progress.ForeColor = vbBlack     '<<<  Black text
    frmSaveTips.Progress.Print Num               '<<<  print percent

    frmSaveTips.Progress.Line (0, 0)-(Work, .ScaleHeight), vbBlue, BF
    .Refresh          '<<<  show
End With
End Sub

'  <<<<<<<<<<<<   event code for form   >>>>>>>>>>>>>>>>>>>

Private Sub Command1_Click()

intcounted = 1000    'whatever..use 100o for this example

'copy the files to the destination directory & increment the count
'do your whatevers..copy files and increment after each file
'progress must be within your loop or whatever

Dim i
For i = 1 To 1000
   Call DoProgress(copied / intTotalCount * 100)   'progress bar set to 100
    Print "This is dumb!"
    copied = copied + 1    'increment for progress bar
 Next i

End Sub
just use a Doevents statement. If your code is looping to fast the CPU will never get a chance to paint the progressbar's change. To test this put a Doevents statement have you change the value of the progressbar. You will not want to keep it there just like that as it will slow down your computer. You will only want to doevents will every ten or so loops.
Put a timer control. Set the timer interval to a satisfactory value. Set the action of the timer to point to your procedure to update the progress bar.
All Courses

From novice to tech pro — start learning today.