PRB: Recursive Use of AddressOf Operator Fails
ID: Q192257
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
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.
MORE INFORMATIONSteps 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.
Additional query words:
kbDSupport kbDSD kbVBp kbVBp500 kbVBp600 kbNoKeyWord
Keywords : kbGrpVB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbprb
|