Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Handling of event raised in other class module

Hi,

I found some very interesting programming stuff that was brought about
in the following:


Public Event SalaryChange(OldAmount As Single, NewAmount As Single,
Cancel As
Boolean)
Property Let Salary(Value As Single)
Dim Cancel As Boolean
RaiseEvent SalaryChange(pSalary, Value, Cancel)
If Cancel = True Then
MsgBox "Salary Change Overruled"
Else
pSalary = Value
End If
End Property

Now, this RaiseEvent statement is interesting in that, as opposed to a
usual procedure call, the event handler procedure called doesn't have
to exist. But the trouble is this:

1) We can't declare WithEvents in the same class or we get a compile
error!
2) The statement WithEvent *must* be in a class module.

The example above would be very useful indeed as a good class
programming example, if it could be finished. Using just the Salary
property, will one of you class gurus please be so kind as to finish
the job and modify/add the proper code in the class where the above
property comes from *and* write the regular module code and event
handler in the second class module so that it all hooks up nicely and
works? (not in the ThisWorkbook or sheet code module but in a regular
class module please).

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Handling of event raised in other class module


VbaNew wrote:
Hi,

I found some very interesting programming stuff that was brought

about
in the following:

Public Event SalaryChange(OldAmount As Single, NewAmount As Single,
Cancel As
Boolean)
Property Let Salary(Value As Single)
Dim Cancel As Boolean
RaiseEvent SalaryChange(pSalary, Value, Cancel)
If Cancel = True Then
MsgBox "Salary Change Overruled"
Else
pSalary = Value
End If
End Property

Now, this RaiseEvent statement is interesting in that, as opposed to

a
usual procedure call, the event handler procedure called doesn't have
to exist. But the trouble is this:

1) We can't declare WithEvents in the same class or we get a compile
error!
2) The statement WithEvent *must* be in a class module.

The example above would be very useful indeed as a good class
programming example, if it could be finished. Using just the Salary
property, will one of you class gurus please be so kind as to finish
the job and modify/add the proper code in the class where the above
property comes from *and* write the regular module code and event
handler in the second class module so that it all hooks up nicely and
works? (not in the ThisWorkbook or sheet code module but in a regular
class module please).

Thanks.


I think you may have misunderstood what an event is for. Please give an
example of when you would want a class to raise an event to notify
itself of a change it is making.

FWIW I think you have messed up the declaration of the event: surely
the OldAmount and NewAmount arguments should be ByVal i.e. why would
you want the client code to change them?

Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Class module Mark[_36_] Excel Programming 2 February 17th 04 03:14 PM
Event Raised by Paste Special + Link cduden Excel Programming 1 January 15th 04 06:50 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"