bart.smissaert@gmail.com
2/23/2012 2:42:00 PM
OK, I got the idea now.
To summarise:
Declare and raise event from the VB6 class with Implements
In a normal class set reference (with WithEvents) to the class with
Implements and pick up events
Then in that second (normal) class raise another event and that event will
be picked up in VBA.
Not quite sure what the difference is with my original scenario (in that
case the VBA class was like
the second VB6 class), but have coded as you suggested, but event not picked
up in VBA.
I have a feeling that the trouble may be to do with what you say here:
> ensure of course,
> that the "MyEventRaiser"-ObjTypeVariable is filled with
> a concrete Instance first (and not remains Nothing).
I do this in the VBA class (called CSQLiteEvents2) like this:
Private WithEvents SQLiteEvents As SQLiteProcs.clsSQLite
Private Sub Class_Initialize()
Set SQLiteEvents = SQLiteProcs.clsSQLite
End Sub
And I initialize the VBA class on startup like this:
Private clsSQLiteEvents As CSQLiteEvents2
Sub InitEventsClass()
If clsSQLiteEvents Is Nothing Then
Set clsSQLiteEvents = New CSQLiteEvents2
End If
End Sub
Is that not sufficient to keep the VB6 class (the second one) alive?
RBS
"Schmidt" <sss@online.de> wrote in message
news:ji5h6b$dir$1@dont-email.me...
> Am 23.02.2012 14:34, schrieb RB Smissaert:
>> Hi Olaf,
>>
>> Slightly confused here:
>>
>> Where in your scenario do you put the Public Event,
>> in the class with Implements or in the other class?
>> The event will need to be public to be available in VBA.
>
> The Events-Declaration-Line(s) belong into the class,
> from where you want to raise them, so - in your case -
> into the class which does the 'Implements IFunction'.
> Let's call those "the EventRaiser"-classes.
>
>> Where do I put the RaiseEvent, in the class with Implements
>> or in the other class?
> An RaiseEvent-attempt in a given class needs a matching
> (accompanying) Events-Declaration in the same Code-Module,
> so these attempts should be placed in "the EventRaiser"
> too (in your case this is also the class, which does the
> Implements IFunction).
>
> Then there's "EventConsumers", which in VB6 can be
> VB-Forms, VB-Usercontrols or any other "normal Class"...
> on the VBA-end these could be Excel-Worksheets or
> any other "normal VBA-Class-Module". In neither case
> is it possible, to use *.bas-Modules as EventConsumers.
>
> Such an EventConsumer-(Class) needs to define(declare)
> the EventRaiser-Class with a special Keyword: WithEvents.
> usually over (adapted to your scenario):
> Private WithEvents MyEventRaiser As cMyRaiserWithImplementsInIt
>
> After this definition was done, you can select the
> declared ObjectVariable (in this example: MyEventRaiser)
> from the appropriate IDE-CodeModule-ComboBox on the left-hand.
> After that, in the right-hand-ComboBox you can select
> the Events, this Raising-Capable classType has to offer.
> And then fill in your Code into the automatically
> inserted EventProc-Definition.
> To receive Events therein, you need to ensure of course,
> that the "MyEventRaiser"-ObjTypeVariable is filled with
> a concrete Instance first (and not remains Nothing).
>
> Maybe play around with that in smaller TestClasses in
> VB6 first - a simple RaiserClass - and a ConsumerClass
> (or a ConsumerForm), to get a grip on the topic first.
>
> Olaf