?
Solved

Move progress bar from another class

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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

770 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