Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
CLASS MODULE & SIMPLE MODULE | Excel Discussion (Misc queries) | |||
Class module | Excel Programming | |||
Event Raised by Paste Special + Link | Excel Programming | |||
Variable from a sheet module in a class module in XL XP | Excel Programming |