Solved

Move progress bar from another class

Posted on 2004-04-09
3
267 Views
Last Modified: 2006-11-17
How would I be able to move a progress bar from a different class than the one it is in?

The progess bar is on a form, while the calculations are in a different class altogether. When I make an instance of the form, I do not reference the original form. I want to call the ORIGINAL progress bar in the form from another class.

Thanks for the help.
0
Comment
Question by:waterzap
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10789974
Raise event from the class. In the form from which you create this class declare class variable with WithEvents keyword. Handle message raised from the class and move progress bar position according to event parameter.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 10791037
Here is a basic example of how to use Events in a class.  

Create a new project and add a Class Module.  Add a CommandButton and a ProgressBar to your form.  Paste the Code below and hit run.

' --------------------------------------------------------------
' Code for Form1
' --------------------------------------------------------------
Option Explicit

Private WithEvents c As Class1

Private Sub Form_Load()
    Set c = New Class1
End Sub

Private Sub Command1_Click()
    Command1.Enabled = False
    c.startProcess
End Sub

Private Sub c_progressChanged(ByVal min As Integer, _
        ByVal value As Integer, ByVal max As Integer)
    ProgressBar1.max = max
    ProgressBar1.min = min
    ProgressBar1.value = value
    ProgressBar1.Refresh
End Sub

Private Sub c_processComplete()
    MsgBox "Done"
    Command1.Enabled = True
End Sub


' --------------------------------------------------------------
' Code for Class1
' --------------------------------------------------------------
Option Explicit

Public Event progressChanged(ByVal min As Integer, _
    ByVal value As Integer, ByVal max As Integer)
Public Event processComplete()

Public Sub startProcess()
    Dim i As Integer
    Dim endTime As Date
   
    For i = 1 To 10
        endTime = DateAdd("s", 1, Now)
        Do
            DoEvents
        Loop While Now < endTime
        RaiseEvent progressChanged(0, i, 10)
    Next i
    RaiseEvent processComplete
End Sub
0
 

Author Comment

by:waterzap
ID: 10797064
Brilliant. Works..thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now