Solved

Please help with the progress bar?

Posted on 1998-12-20
4
141 Views
Last Modified: 2010-05-03
I like to do a progress bar on a form which is updating counts from another form which is doing a process.the "progress form" must also have a cancel button.
Something like when we use a scanner.
Thank you
0
Comment
Question by:santhiran
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:trillo
ID: 1451665
Supose
PrgForm = Form with the progress bar
Form1 = Form with iterating process
And now let's say your iterating process looks like:

Private Sub Iterate()
    PrgForm.Show
    PrgForm.ProgressBar1.Min=0
    PrgForm.ProgressBar1.Max=1000
    For i=0 to 1000
          ..... do something.....
        PrgForm.ProgressBar1.Value = i
    Next i
End Sub

This code will work but it has some inconvenients:
1) When you load PrgForm... It can't be modal, because your process wouldn't never update... and if it is not modal, the user could click on Form1, without knowing that a process is running (Form1 would be overlapping PrgForm) and he would think there's something wrong.
2) You should mantain a global variable or flag to know when the user pressed the Cancel button. And you should avoid, when possible, using global variables (it takes more memory).

I would suggest the following:
1) You place your procedure on a module file ( .bas ).
2) When you start the process you invoke PrgForm to load modal, this will avoid user's confusion.
3) On the PrgForm's Activate event you call the process. If you put the code in the Form Load event, you'll never see the progress, that's why you should put it in the Activate event.

It would look something like:
'PrgForm Activate event
Private Sub Form_Activate (...)
    PrgFormCancelled = False   ' Set flag to false
    Me.Refresh     ' Necessary in order to show the controls.
    Call UpdateProc
End Sub

'The Cancel button's Click event
Private Sub Cancel_click (...)
     PrgFormCancelled = True    'Set flag to True
End Sub

You need to declare the PrgFormCancelled flag as public in the module file.
Public PrgFormCancelled as Boolean

Your update procedure (in a module file) would look like:
Public Sub UpdateProc()
    PrgForm.ProgressBar1.Min=0
    PrgForm.ProgressBar1.Max=1000
    For i=0 to 1000
          ..... do something.....
        PrgForm.ProgressBar1.Value = i
        DoEvents
        If PrgFormCancelled = True Then
            Unload PrgForm
        End If
    Next i
End Sub

The DoEvents statement is important, in order to giva a chance to the Cancel button to be pressed.

Trillo
0
 

Author Comment

by:santhiran
ID: 1451666
I do not want to use the module file because I want to use the same progress bar form for other forms too. Please help for the process involved in the backgroung form is a bit complex.
Thank you.
0
 

Author Comment

by:santhiran
ID: 1451667
I do not want to use the module file because I want to use the same progress bar form for other forms too. Please help for the process involved in the backgroung form is a bit complex.
Thank you.
0
 
LVL 2

Accepted Solution

by:
trillo earned 100 total points
ID: 1451668
That's not a problem... you could use the same progress form and progress bar for multiple processes.... Just pass the form (or the progressbar, as a parameter of the routine.

Public Sub UpdateProc(PrgForm as Form)
    PrgForm.ProgressBar1.Min=0
    PrgForm.ProgressBar1.Max=1000
    For i=0 to 1000
          ..... do something.....
        PrgForm.ProgressBar1.Value = i
        DoEvents
        If PrgFormCancelled = True Then
            Unload PrgForm
        End If
    Next i
End Sub

Trillo
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now