PC Review


Reply
 
 
E.Z.
Guest
Posts: n/a
 
      18th May 2009
Hello,
Doe's "AddressOf" works with Excel macros?
I keep getting a Compile Error for using it.
"Invalid use of AddressOf operator"

This is the code:

Private Sub TestSub()
i = 0
End Sub

Private Function GetAddr(ByVal Addr As Long) As Long
GetAddr = Addr
End Function

Private Sub Test()
Dim Addr as Long
Addr = GetAddr (AddressOf TestSub)
End Sub

The error is for Test Sub
Tnx


 
Reply With Quote
 
 
 
 
Tim Zych
Guest
Posts: n/a
 
      18th May 2009
I don't have much experience with AddressOf, but from what I can see, if
TestSub is moved to a regular module that should fix it.

From my book "VB and VBA In a Nutshell" by Paul Lomax:

AddressOf Operator
Rules at a Glance:
"The callback function must be stored in a code module; attempting to store
it in a class or form module generates a compile-time error, "Invalid use of
AddressOf operator."

When I tested your code, with TestSub moved to a regular code module, it
worked.


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"E.Z." <(E-Mail Removed)> wrote in message
news:egZ1Sf$(E-Mail Removed)...
> Hello,
> Doe's "AddressOf" works with Excel macros?
> I keep getting a Compile Error for using it.
> "Invalid use of AddressOf operator"
>
> This is the code:
>
> Private Sub TestSub()
> i = 0
> End Sub
>
> Private Function GetAddr(ByVal Addr As Long) As Long
> GetAddr = Addr
> End Function
>
> Private Sub Test()
> Dim Addr as Long
> Addr = GetAddr (AddressOf TestSub)
> End Sub
>
> The error is for Test Sub
> Tnx
>
>



 
Reply With Quote
 
E.Z.
Guest
Posts: n/a
 
      19th May 2009
Tnx a lot,
What do you mean by "regular code module"?

"Tim Zych" <tzych@nospam at earthlink dot net> wrote in message
news:ekn$(E-Mail Removed)...
>I don't have much experience with AddressOf, but from what I can see, if
>TestSub is moved to a regular module that should fix it.
>
> From my book "VB and VBA In a Nutshell" by Paul Lomax:
>
> AddressOf Operator
> Rules at a Glance:
> "The callback function must be stored in a code module; attempting to
> store it in a class or form module generates a compile-time error,
> "Invalid use of AddressOf operator."
>
> When I tested your code, with TestSub moved to a regular code module, it
> worked.
>
>
> --
> Regards,
> Tim Zych
> http://www.higherdata.com
> Workbook Compare - Excel data comparison utility
>
> "E.Z." <(E-Mail Removed)> wrote in message
> news:egZ1Sf$(E-Mail Removed)...
>> Hello,
>> Doe's "AddressOf" works with Excel macros?
>> I keep getting a Compile Error for using it.
>> "Invalid use of AddressOf operator"
>>
>> This is the code:
>>
>> Private Sub TestSub()
>> i = 0
>> End Sub
>>
>> Private Function GetAddr(ByVal Addr As Long) As Long
>> GetAddr = Addr
>> End Function
>>
>> Private Sub Test()
>> Dim Addr as Long
>> Addr = GetAddr (AddressOf TestSub)
>> End Sub
>>
>> The error is for Test Sub
>> Tnx
>>
>>

>
>



 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      19th May 2009
In the VBE -> Insert -> Module.


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"E.Z." <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Tnx a lot,
> What do you mean by "regular code module"?
>
> "Tim Zych" <tzych@nospam at earthlink dot net> wrote in message
> news:ekn$(E-Mail Removed)...
>>I don't have much experience with AddressOf, but from what I can see, if
>>TestSub is moved to a regular module that should fix it.
>>
>> From my book "VB and VBA In a Nutshell" by Paul Lomax:
>>
>> AddressOf Operator
>> Rules at a Glance:
>> "The callback function must be stored in a code module; attempting to
>> store it in a class or form module generates a compile-time error,
>> "Invalid use of AddressOf operator."
>>
>> When I tested your code, with TestSub moved to a regular code module, it
>> worked.
>>
>>
>> --
>> Regards,
>> Tim Zych
>> http://www.higherdata.com
>> Workbook Compare - Excel data comparison utility
>>
>> "E.Z." <(E-Mail Removed)> wrote in message
>> news:egZ1Sf$(E-Mail Removed)...
>>> Hello,
>>> Doe's "AddressOf" works with Excel macros?
>>> I keep getting a Compile Error for using it.
>>> "Invalid use of AddressOf operator"
>>>
>>> This is the code:
>>>
>>> Private Sub TestSub()
>>> i = 0
>>> End Sub
>>>
>>> Private Function GetAddr(ByVal Addr As Long) As Long
>>> GetAddr = Addr
>>> End Function
>>>
>>> Private Sub Test()
>>> Dim Addr as Long
>>> Addr = GetAddr (AddressOf TestSub)
>>> End Sub
>>>
>>> The error is for Test Sub
>>> Tnx
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
E.Z.
Guest
Posts: n/a
 
      19th May 2009
Yup, got it. works.
Tnx again


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AddressOf from VB6 to .Net VB pavel.orehov@gmail.com Microsoft VB .NET 3 22nd Mar 2006 09:33 PM
how to used ADDRESSOF in vb.net Supra Microsoft VB .NET 4 30th Mar 2005 07:32 PM
AddressOf VB.net peter Microsoft VB .NET 1 26th Sep 2004 05:23 PM
AddressOf JonWayn Microsoft Access VBA Modules 2 28th Feb 2004 07:24 PM
No AddressOf in C# ECVerify.com Microsoft C# .NET 6 30th Jan 2004 03:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:27 AM.