Solved

Move progress bar from another class

Posted on 2004-04-09
3
268 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now