Microsoft KB Archive/192257

= PRB: Recursive Use of AddressOf Operator Fails =

Article ID: 192257

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q192257



SYMPTOMS
If you use "AddressOf MyFunc" in the function, or Subroutine "MyFunc" in the standard module, Visual Basic compiler will generate an error message:

"Expected Sub, Function, or Property"



RESOLUTION
Include the module name when you use the AddressOf Operator. For example, use: AddressOf MyModule.MyFunc instead of: AddressOf MyFunc



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Form1 is created by default.  From the Project menu, add a standard Module, Module1, and insert the following code: Declare Function EnumChildWindows Lib "user32" ( _             ByVal hWndParent As Any, ByVal lpEnumFunc As Long, _              ByVal lParam As Long) As Long

Declare Function FindWindowEx Lib "user32" Alias _ "FindWindowExA" (ByVal hWnd1 As Long, _             ByVal hWnd2 As Long, ByVal lpsz1 As String, _              ByVal lpsz2 As String) As Long

Dim m_hWnd As Long

Public Function EnumWindowProc(ByVal hWnd As Long, _             ByVal lParam As Long) As Long

Dim nRet As Long

nRet = FindWindowEx(hWnd, 0, "VbaWindow", "Immediate") If nRet Then m_hWnd = nRet EnumWindowProc = False Else Call EnumChildWindows(hWnd, AddressOf EnumWindowProc, 0) EnumWindowProc = (m_hWnd = 0) End If    End Function  From the Run menu, pick "Start with Full Compile" or press the CTRL+F5 key combination. You will get the error message:

Compile error:

Expected Sub, Function, or Property

 Click OK to dismiss the error message. "AddressOf EnumWindowProc" should be highlighted.  Edit this line to add the module name so that it looks like this: Call EnumChildWindows(hWnd, AddressOf Module1.EnumWindowProc, 0)  Repeat step 3 and note that the project runs without an error message.</li></ol>

Additional query words: kbDSupport kbDSD kbVBp kbVBp500 kbVBp600 kbNoKeyWord

Keywords: kbprb KB192257

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.