Events not firing 
Author Message
 Events not firing

I have a vb project that inclused a class module and a
form. In the class module I have declared the following:
Private WithEvents mForm As frmDisplayServiceCalDetails
In the class module there is then an event handler called
mForm_ViewAsset which takes one long parameter. So in the
form I have declared the event as follows:
Public Event ViewAsset(lngAssetID As Long)
I then raise this event in the form using the raiseEvent
keyword and Passing a long parameter. For some reason the
event is not firing. I don't get an error or anything it
just runs through the code but when it comes to the line
where the event is raised nothing happens. Does anyone
have any idea what I am doing wrong?

thanks,
Annemarie



Fri, 24 Sep 2004 19:20:25 GMT  
 Events not firing

were released on Mon, 8 Apr 2002 04:20:25 -0700 bearing the
following fruit:

Quote:
>I have a vb project that inclused a class module and a
>form. In the class module I have declared the following:
>Private WithEvents mForm As frmDisplayServiceCalDetails
>In the class module there is then an event handler called
>mForm_ViewAsset which takes one long parameter. So in the
>form I have declared the event as follows:
>Public Event ViewAsset(lngAssetID As Long)
>I then raise this event in the form using the raiseEvent
>keyword and Passing a long parameter. For some reason the
>event is not firing. I don't get an error or anything it
>just runs through the code but when it comes to the line
>where the event is raised nothing happens. Does anyone
>have any idea what I am doing wrong?

I think you'll have to post a small code snippet.

J



Fri, 24 Sep 2004 19:38:04 GMT  
 Events not firing

Quote:
>-----Original Message-----

>were released on Mon, 8 Apr 2002 04:20:25 -0700 bearing
the
>following fruit:

>>I have a vb project that inclused a class module and a
>>form. In the class module I have declared the following:
>>Private WithEvents mForm As frmDisplayServiceCalDetails
>>In the class module there is then an event handler
called
>>mForm_ViewAsset which takes one long parameter. So in
the
>>form I have declared the event as follows:
>>Public Event ViewAsset(lngAssetID As Long)
>>I then raise this event in the form using the raiseEvent
>>keyword and Passing a long parameter. For some reason
the
>>event is not firing. I don't get an error or anything it
>>just runs through the code but when it comes to the line
>>where the event is raised nothing happens. Does anyone
>>have any idea what I am doing wrong?

>I think you'll have to post a small code snippet.

>J
>.

This code appears in the form:

Public Event ViewAsset(lngAssetID As Long)

Private Sub cmdDisplay_Click()

    Me.Hide

    RaiseEvent ViewAsset(Val(lvwDetails.SelectedItem.Tag))

    Unload Me

End Sub

The following is in the class module:

Private WithEvents mForm As frmDisplayServiceCalDetails

Private Sub mForm_ViewAsset(lngAssetID As Long)
    msgbox "In event ViewAsset"
End Sub



Fri, 24 Sep 2004 20:14:36 GMT  
 Events not firing
Where do you ever set a reference for mForm in the class?

Public Property Set MyForm (frm as form)
    Set mForm = MyForm
end property
Public Property Get MyForm (frm as form)
    Set MyForm = mForm
end property

Form Code...
(After creating the instance of the class...)
Set SomeClass.MyForm = Me

D.

|

Quote:
| >-----Original Message-----

| >were released on Mon, 8 Apr 2002 04:20:25 -0700 bearing
| the
| >following fruit:
| >
| >>I have a vb project that inclused a class module and a
| >>form. In the class module I have declared the following:
| >>Private WithEvents mForm As frmDisplayServiceCalDetails
| >>In the class module there is then an event handler
| called
| >>mForm_ViewAsset which takes one long parameter. So in
| the
| >>form I have declared the event as follows:
| >>Public Event ViewAsset(lngAssetID As Long)
| >>I then raise this event in the form using the raiseEvent
| >>keyword and Passing a long parameter. For some reason
| the
| >>event is not firing. I don't get an error or anything it
| >>just runs through the code but when it comes to the line
| >>where the event is raised nothing happens. Does anyone
| >>have any idea what I am doing wrong?
| >>
| >
| >I think you'll have to post a small code snippet.
| >
| >J
| >.
|
| This code appears in the form:
|
| Public Event ViewAsset(lngAssetID As Long)
|
| Private Sub cmdDisplay_Click()
|
|     Me.Hide
|
|     RaiseEvent ViewAsset(Val(lvwDetails.SelectedItem.Tag))
|
|     Unload Me
|
| End Sub
|
| The following is in the class module:
|
| Private WithEvents mForm As frmDisplayServiceCalDetails
|
| Private Sub mForm_ViewAsset(lngAssetID As Long)
|     msgbox "In event ViewAsset"
| End Sub
|



Fri, 24 Sep 2004 21:28:23 GMT  
 Events not firing
Hi,

You can raise events in Form code from code in a class (object), not the
other way around.  To receive an event, the code in question must have a
Windows message handler.  Class modules (actually, the object instantiated
from a class, not the class itself) has no message handler.  This has
changed in Visual Studio .NET, where events are handled differently.
However, VB6 and earlier...

In you specific example, simply call a method in the class.  There is no
need for an event.

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sat, 25 Sep 2004 00:43:50 GMT  
 Events not firing

Quote:

> Hi,

Yes, you certainly must be high.  Stop smoking so much Redmond Gold!

Quote:
> You can raise events in Form code from code in a class (object), not the
> other way around.  To receive an event, the code in question must have a
> Windows message handler.  Class modules (actually, the object instantiated
> from a class, not the class itself) has no message handler.  This has
> changed in Visual Studio .NET, where events are handled differently.
> However, VB6 and earlier...

Idiot.  Go practice your worthless Evangelism.NET elsewhere, mmkay?

Quote:
> In you specific example, simply call a method in the class.  There is no
> need for an event.

Here's sample code for Form1:

----
Option Explicit

Public Event ASAP(ByVal When As Single)

Public Property Get Loaded() As Boolean
  Dim F As Form
  For Each F In Forms
    If F Is Me Then Loaded = True: Exit For
  Next
End Property

Private Sub Command1_Click()
  Me.Hide
  RaiseEvent ASAP(Timer)
  Unload Me
End Sub
----

Here's sample code for Class1:

----
Option Explicit

Private WithEvents GFY As Form1

Private Sub Class_Initialize()
  Set GFY = New Form1
  GFY.Show
End Sub

Private Sub Class_Terminate()
  If GFY.Loaded Then Unload GFY
End Sub

' Look, ma, no Windows message handler!
Private Sub GFY_ASAP(ByVal When As Single)
  Debug.Print "GFY_ASAP ("; When; ") called"
End Sub
----

--
Joe Foster <mailto:jlfoster%40znet.com>  Sign the Check! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 25 Sep 2004 02:02:37 GMT  
 Events not firing
Joe's reply is offensive and childish, but he's right about the code.
There's no inherent problem about receiving events in a class, nor in firing
them from a form.


Quote:
> Hi,

> You can raise events in Form code from code in a class (object), not the
> other way around.  To receive an event, the code in question must have a
> Windows message handler.  Class modules (actually, the object instantiated
> from a class, not the class itself) has no message handler.  This has
> changed in Visual Studio .NET, where events are handled differently.
> However, VB6 and earlier...

> In you specific example, simply call a method in the class.  There is no
> need for an event.

> --
> Richard Grier  (Microsoft Visual Basic MVP)

> See www.hardandsoftware.net for contact information.

> Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
> Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sat, 25 Sep 2004 06:19:00 GMT  
 Events not firing
Hi Joe,

What did I do to cause you a problem?  I do not suggest anyone take up .NET.
I certainly don't evangelize it.  While I like it for some things, it isn't
for everyone...  Also, I don't use it for ANY production code (as of today).
So, I am not an evangelist.

BTW, while your code can work, what is happening?  An event is being raised
in the FORM and is calling a method in the class.  The class is not
receiving the event (the form object GFY provides the message processing
loop as a surogate).

Have you actually been able to do this in some other way that does not
involve a form?  If so, I'd be happy to see it.

It is my experience that the people who are the loudest should often be
silent.  Of course, I have been wrong before, so I would not be surprised to
have it happen again.  Perhaps it has here, but I am not convinced.

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sat, 25 Sep 2004 08:13:53 GMT  
 Events not firing
Hi,

There's no inherent problem about receiving events in a class, nor in firing
them from a form.
<<

I didn't say that there was problem raising an event from a form.  I just
know of no way to receive them in a non-form object.  The example that Joe
used to illustrate his statement doesn't convince me that a form is not
involved.  Do you have an example that show such a thing?  Joe's example
uses a form's message loop (GFY) instantiated in the class code.  His
example only supports my statement.

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sat, 25 Sep 2004 08:17:48 GMT  
 Events not firing

Quote:

> What did I do to cause you a problem?  I do not suggest anyone take up .NET.
> I certainly don't evangelize it.  While I like it for some things, it isn't
> for everyone...  Also, I don't use it for ANY production code (as of today).
> So, I am not an evangelist.

You're lying about capabilities Classic VB has had since VB5, so
obviously you have /some/ ulterior agenda, you weasel.  Anyway,
suppose you tell us all where the magic mystery form is in here:

----Module1----
Option Explicit

Private Sub Main()
  Dim ESAD As Class2, FOAD As Class2, RSN As Class1

  Set RSN = New Class1

  Set ESAD = New Class2
  Set ESAD.Punk = RSN

  Set FOAD = New Class2
  Set FOAD.Punk = RSN

  RSN.Bonk
End Sub
----End Module1----

----Class1----
Option Explicit

Public Event ASAP()

Public Sub Bonk()
  RaiseEvent ASAP
End Sub
----End Class1----

----Class2----
Option Explicit

Private WithEvents GFY As Class1

Friend Property Set Punk(ByVal MMkay As Class1)
  Set GFY = MMkay
End Property

Private Sub GFY_ASAP()
  Debug.Print Hex$(ObjPtr(Me)); ": Oif"
End Sub
----End Class2----

--
Joe Foster <mailto:jlfoster%40znet.com>   L. Ron Dullard <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 25 Sep 2004 12:07:24 GMT  
 Events not firing
Get a life, Joe.




Quote:

> > What did I do to cause you a problem?  I do not suggest anyone take up
.NET.
> > I certainly don't evangelize it.  While I like it for some things, it
isn't
> > for everyone...  Also, I don't use it for ANY production code (as of
today).
> > So, I am not an evangelist.

> You're lying about capabilities Classic VB has had since VB5, so
> obviously you have /some/ ulterior agenda, you weasel.  Anyway,
> suppose you tell us all where the magic mystery form is in here:

> ----Module1----
> Option Explicit

> Private Sub Main()
>   Dim ESAD As Class2, FOAD As Class2, RSN As Class1

>   Set RSN = New Class1

>   Set ESAD = New Class2
>   Set ESAD.Punk = RSN

>   Set FOAD = New Class2
>   Set FOAD.Punk = RSN

>   RSN.Bonk
> End Sub
> ----End Module1----

> ----Class1----
> Option Explicit

> Public Event ASAP()

> Public Sub Bonk()
>   RaiseEvent ASAP
> End Sub
> ----End Class1----

> ----Class2----
> Option Explicit

> Private WithEvents GFY As Class1

> Friend Property Set Punk(ByVal MMkay As Class1)
>   Set GFY = MMkay
> End Property

> Private Sub GFY_ASAP()
>   Debug.Print Hex$(ObjPtr(Me)); ": Oif"
> End Sub
> ----End Class2----

> --
> Joe Foster <mailto:jlfoster%40znet.com>   L. Ron Dullard

<http://www.xenu.net/>

- Show quoted text -

Quote:
> WARNING: I cannot be held responsible for the above        They're
coming  to
> because  my cats have  apparently  learned to type.        take me away,
ha ha!



Sat, 25 Sep 2004 12:25:21 GMT  
 Events not firing
I've got any number of class modules (in VB and VBA) that have statements
like

Private WithEvents mDocument        As Word.Document
Private WithEvents mEventControl    As Office.CommandBarButton
Private Withevents mMySilkClass     as SilkClass

All of which merrily receive events from the referenced objects. And in my
case, very few of the event-raising objects is a form.


Quote:
> Hi,

> There's no inherent problem about receiving events in a class, nor in
firing
> them from a form.
> <<

> I didn't say that there was problem raising an event from a form.  I just
> know of no way to receive them in a non-form object.  The example that Joe
> used to illustrate his statement doesn't convince me that a form is not
> involved.  Do you have an example that show such a thing?  Joe's example
> uses a form's message loop (GFY) instantiated in the class code.  His
> example only supports my statement.

> --
> Richard Grier  (Microsoft Visual Basic MVP)

> See www.hardandsoftware.net for contact information.

> Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
> Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sat, 25 Sep 2004 12:24:41 GMT  
 Events not firing

Quote:

> Get a life, Joe.

I had one, but that was before the Migration Lizard got at my code...

--
Joe Foster <mailto:jlfoster%40znet.com>  KrazyKookKultz! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 25 Sep 2004 13:17:23 GMT  
 Events not firing
I haven't told a lie to you or any one else.  If I made a mistake, it was
simply a mistake.

You obviously have a serious mental defect.  I suggest that you seek
professional help.  Of course, my suggestion to you will be ill received.
But, who can expect more?

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sun, 26 Sep 2004 00:42:06 GMT  
 
 [ 30 post ]  Go to page: [1] [2] [3]

 Relevant Pages 

1. click event not firing if lost_focus is firing first

2. Terminate Event not Fired

3. BeforeDelConfirm, AfterDelConfirm events not firing

4. Inspector_Close Event Not Firing

5. Form events not firing in public folder

6. CheckBox events not firing?

7. Events not firing under on Import...

8. combo box Click event not firing

9. Shape Added Event Not Firing

10. Open event not fired?

11. Application.Quit: events not fired ??

12. Button Click Event Not Firing !

 

 
Powered by phpBB® Forum Software