?
Solved

Move progress bar from another class

Posted on 2004-04-09
3
Medium Priority
?
277 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 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

830 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