Trouble with Events

DaveP

Member
Joined
Jan 24, 2008
Messages
12
Programming Experience
1-3
I am building a DLL which does a lot of number crunching and consists of a Class Module with the Public declarations and some Modules with lots of maths sub routines.
I want to raise an event in a module which will update a progeress bar in the calling application.
So in my Class Module Thermal I have

Public Event MyProgress(ByVal percentDone As Single, ByVal IterationNo As Integer)

Public Sub UpdateProgressBar()
RaiseEvent MyProgress(progress, iter)
End Sub

and in my module I call Thermal.UpdateProgressBar()
this gives an error because it says the UpdateProgressBar is not declared.

if I make the Sub Public Shared my module can now call the Sub but I get an error
at the RaiseEvent Cannot refer to an instance of a class from within a shared method or shared member initializer without an explicit instance of the class.

Can anyone point me at a solution to this problem
 
You know what a car is right? But, can you just say "drive car" and be driving a car? Of course not. You have to actually have a car first to be able to drive it. The same goes here. As you've shown it, UpdateProgressBar is an instance member, i.e. each instance of the class has an UpdateProgressBar method. To be able to call the method, you have to have created an instance first.

By declaring the method Shared you make it a member of the class itself rather than of any particular instance of the class, but then the method can't raise the event because the event is not Shared. Either neither are Shared and you create an instance or both are Shared.
 
But the Application which is calling this dll creates the instance with

Friend WithEvents RemoteDLL As New STTall.Thermal
 
Back
Top