Results 1 to 6 of 6

Thread: UDT Question

  1. #1

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Resolved 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.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Post the declaration for the arrays and the procedure.
    Post the code that calls the procedure.

  3. #3

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    Ok The following were declared in a module

    VB Code:
    1. Public Type typMenu
    2.      NodeVisible As Boolean
    3.      NodeDepth As Long            
    4.      NodeType As String
    5.      NodeItem As Variant
    6.      IconSource As String  
    7.      ForeColor As Long
    8.      BackColor As Long
    9.      MousoverEvent As String  
    10.      FollowingNode As Long
    11.      ListOfItems() As String    
    12.      End Type
    13. Public GMenu() As typMenu
    14. Public LPlanMenu() As typMenu

    My calling code from a form is ....
    VB Code:
    1. Sub HelpLabel_Click()
    2.      Call DoMenu2(GMenu, Me)          
    3. End Sub

    The Procedure code in a module is ....
    VB Code:
    1. Sub DoMenu2(DoMenu As typMenu, MenuForm As Form, _
    2.                     Optional NodeID As Long = 0, _
    3.                     Optional HotItem As String = "Clear")
    4. End Sub

    The byref occurs on GMenu in the calling code but I can't understand why.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    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.

  5. #5

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    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.

    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  6. #6
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    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
  •  



Click Here to Expand Forum to Full Width