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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add a Process Indicator ?

Status
Not open for further replies.

snehakevin

Technical User
Sep 14, 2003
33
0
0
SG
My application is in VB. One of my option in the application is to create excel files in a required format.
The process takes more than 3minutes. I want to show a process bar on the screen. I tried with timer event..
but it is not working or I may not used in the right way..

The code is like this..

Private Sub Timerreport_Timer()
If Timerreport.Interval = 50 Then
MsgBox "Please Wait Your Request is Being Processed"
End If
End Sub

Please help
 
Hi snehakevin,

I think the control you need is the "progressbar". You will need to add the "Microsoft Windows Common Controls" to your project by clicking project->components in vb IDE.

regards,
nicsin
 
Thank u nicsin,

I have added the progressbar, how to use it?
can you explain little bit....
 
if you just want it to tell people that it's running, you could try using the Excel object that you have defined as a test. If you get an error then it means the object is not being used, hence has finished, and you can stop showing the message.. for instance

timer1_timer()
checkstatus ( i think you need to put the error checking routine into a sub or function of its own so that the Err variable gets cleared, otherwise it will always return an error even when there is not one)
end sub


private function checkstatus()
on error goto jobdone (an error means job has completed)
label1.caption = EXCELOBJECT.variable

(substitute EXCELOBJECT for the name of your defined excel object and substitute variable for any of the variables you use that would return a string if the object was still open)

msgbox "job is still running"
exit function

jobdone:
msgbox "Job has ended"
end function
 
Sure. Create a new project in vb and add a progressbar. extend it so it has the same width as the form and add this code:

Option Explicit

Private Sub Form_Load()
Dim i As Long
Me.Show
With ProgressBar1
.Max = 100000
.Value = 0

For i = 0 To 100000
.Value = i
Next

End With
End Sub


it is not perfect but it will give you an indication of how the progressbar is used. Also click n the control and press F1 to see vb help.

regards,
nicsin
 
To demonstrate a simple example of using the progress bar add a command button (Command1), a timer (Timer1) and a progress bar (ProgressBar1). Add the following code to your form:
Code:
Private Sub Command1_Click()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
If ProgressBar1.Value < 100 Then
    ProgressBar1.Value = ProgressBar1.Value + 10
End If
End Sub
This demonstrates how to use it in a very simple way. To modify it to your needs you will have to decide whether you will

1) Base the increment on the total time taken as an estimate (e.g. the 3 minutes you stated)
2) Return certain status indicators from your function (e.g. Part 1 has been completed and therefore it is 25% complete)

Now option 1 isn't very accurate as what happens if it takes 4 minutes (microsoft don't seem to mind too much when showing you a progress bar though :)) so for a more accurate approach you may decide to use option 2. I suppose it really depends how important accuracy is to you.

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

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Also, if you have a loop or DoUntil something in your code you can use that to gauge the value of the progressbar

If you have to use something like ca8msm's Option1 Above You could have a timer set the progressbar to an additional value of 25 every minute, but dont allow the timer to fill the progress bar past 75% then have your code complete the progressbar to 100% when it finishes creating the excel file, it will complete the progressbar exactly on time for you (but may sit on 75% longer than it did on say 25% or 50%)
 
I tried all your suggestions but it does not work.

I have put your code (ca8msm's code above) in a new form, it works when I click the command button, but it does not work in my procedure of creating the excel sheets.

I cant figure out the problem....
 
In your loop where you're writing to the Excel worksheet, put a call to the function that updates the progressbar, and then include a call to DoEvents.

One caution: You need to make sure the form with the progressbar was opened as a modal dialog (parameter on the Show method) in order to prevent the user from clicking on the rest of your application and messing stuff up (DoEvents will allow other GUI events thru, so you need to make sure that the user can't click anywhere but on the &quot;please wait&quot; form to prevent reentrancy problems).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top