Solved

Move progress bar from another class

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

Independent Software Vendors: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

726 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