|
-
Oct 1st, 2004, 03:17 AM
#1
Thread Starter
Frenzied Member
UDT Question
I am declaring a UDT in a module. I am also declaring a 2 arrays of the UDT in the same module. So both the UDT and the UDT arrays are public scope ( and declared as such).
I want to operate on either array using a single subroutine and so I am passing each array into the procedure using Byref, but I am getting the "Byref Argument type mismatch" error. Even though in the target subroutine I am setting the argument type to that of the UDT type.
I don't want to use classes to get around this if I can help it. Can anyone shed some light on this for me please?
Last edited by David.Poundall; Oct 1st, 2004 at 10:56 AM.
-
Oct 1st, 2004, 10:18 AM
#2
Post the declaration for the arrays and the procedure.
Post the code that calls the procedure.
-
Oct 1st, 2004, 10:36 AM
#3
Thread Starter
Frenzied Member
Ok The following were declared in a module
VB Code:
Public Type typMenu
NodeVisible As Boolean
NodeDepth As Long
NodeType As String
NodeItem As Variant
IconSource As String
ForeColor As Long
BackColor As Long
MousoverEvent As String
FollowingNode As Long
ListOfItems() As String
End Type
Public GMenu() As typMenu
Public LPlanMenu() As typMenu
My calling code from a form is ....
VB Code:
Sub HelpLabel_Click()
Call DoMenu2(GMenu, Me)
End Sub
The Procedure code in a module is ....
VB Code:
Sub DoMenu2(DoMenu As typMenu, MenuForm As Form, _
Optional NodeID As Long = 0, _
Optional HotItem As String = "Clear")
End Sub
The byref occurs on GMenu in the calling code but I can't understand why.
-
Oct 1st, 2004, 10:50 AM
#4
The problem is there is a mismatch in that the Sub expected a single element (or "record") of the UDT, not the whole array. If you want to pass the whole array, you need to add parentheses in the Sub declaration:
Sub DoMenu2(DoMenu() As typMenu, ...
"It's cold gin time again ..."
Check out my website here.
-
Oct 1st, 2004, 10:55 AM
#5
Thread Starter
Frenzied Member
Thanks Bruce and Bruce. That sorted it. I always thought that the () parenthasis was optional on array declaration. I will be more literal in my coding in future.
-
Oct 1st, 2004, 11:01 AM
#6
The parens are optional in the call statement, but not the Sub itself ... Glad to help.
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|