AddressOf Operator
Syntax AddressOf [expr.]name
Group Operator
Description
Return a delegate for the expr macro/module's Sub or
Function matching name.
A delegate's Sub or Function is called
using the delegate's Invoke method.
Note: The AddressOf operator returns
an object which holds a weak reference to the macro/module. If no other
references to the macro/module exist then the macro/module reference is deleted
and using the result of the AddressOf operator causes a run-time error.
Parameter Description
expr This is a macro/module reference. If omitted then the current macro/module's reference (Me) is used.
name Return a delegate for this Sub or Function.
See Also Delegate.
Example
'#Language
"WWB-COM"
Delegate Function OpType(ByVal v1 As Variant,
ByVal v2 As Variant) As Variant
SubMain
Debug.Print DoOp(AddressOf
Add,1,2) ' 3
Debug.Print DoOp(AddressOf
Subtract,1,2) '-1
End Sub
Function DoOp(ByVal op
As OpType,
_
ByVal v1 As Variant, ByVal v2 As Variant) As
Variant
DoOp = op.Invoke(v1,v2)
EndFunction
Function Add(ByVal v1 As Variant, ByVal v2
As Variant) As Variant
Add =
v1+v2
End Function
Function Subtract(ByVal v1 As
Variant, ByVal v2 As Variant) As
Variant
Subtract = v1-v2
EndFunction