?
Solved

Please help with the progress bar?

Posted on 1998-12-20
4
Medium Priority
?
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

752 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