Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,779
- Office Version
- 2016
- Platform
- Windows
Hi Dear all.
Strictly speaking RaiseEvent is not a procedure but looks and does the same as one (ie: Executes code) . It also accepts arguments which can be passed ByVal or ByRef.
When an argument is passed ByRef to a Sub/Function , the procedure can modify the argument itself however this doesn't seem to be the case with RaiseEvent. Is this a known bug documented somewhere as i can't find a logic explanation to this problem.
Here is an example :
1-Class named (EventCls)
2- Class named (EventHandlerCls)
3- Bas Module (Caller)
Hope someone can give me some pointers.
Regards.
Strictly speaking RaiseEvent is not a procedure but looks and does the same as one (ie: Executes code) . It also accepts arguments which can be passed ByVal or ByRef.
When an argument is passed ByRef to a Sub/Function , the procedure can modify the argument itself however this doesn't seem to be the case with RaiseEvent. Is this a known bug documented somewhere as i can't find a logic explanation to this problem.
Here is an example :
1-Class named (EventCls)
Code:
Event EventTest(ByRef Cancel As Boolean)
Public Sub RaiseEventTest()
Dim Cancel As Boolean
Cancel = False
RaiseEvent EventTest(Cancel)
MsgBox Cancel [COLOR=seagreen]'Should return TRUE as the Cancel arg is passed ByRef[/COLOR]
End Sub
2- Class named (EventHandlerCls)
Code:
Dim WithEvents EventHandler As EventCls
Private Sub EventHandler_EventTest(ByRef Cancel As Boolean)
[COLOR=seagreen]'Modify argument[/COLOR]
Cancel = True
End Sub
3- Bas Module (Caller)
Code:
Dim oEvent As EventCls
Sub Main()
Set oEvent = New EventCls
oEvent.RaiseEventTest
End Sub
Hope someone can give me some pointers.
Regards.