Why would it be illegal to use AddressOf in a Class?
Printable View
Why would it be illegal to use AddressOf in a Class?
I'm not sure but it wouldn't work, if you have several objects running, how can you address one or them (which one?) And what if you don't have any objects of that class at all?
It just only works with modules since they are there until your app is terminated
you can only use the AddressOf Operator on Public Functions that you write yourself, that are contained in a class module.
for example you couldnt use it on an API call, or a private function, or anything inside a form(like Command1_Click)
also you have to use AddressOf as a Parameter in a function. for example this
wuld be illegal but thisCode:Dim lngAddress as Interger
Private Sub Form_Load()
lngAddress = AddressOf MyFunction
End Sub
is fine.Code:Private Sub Form_Load()
lngAddress = GetValue(AddressOf MyFunction)
End Sub
Private Function GetValue(Value as Long)
GetValue = Value
End Function