Solved

Please help with the progress bar?

Posted on 1998-12-20
4
143 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

777 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