Results 1 to 3 of 3

Thread: Help sorting array of UDTs

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    I am trying to sort and array of UDTs using a sub but I get the follow error. Does anybody know what I am doing wrong?

    "Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types"

    Code:
    Type UserInformation
        UserID As String * 16
        UserName As String
        OSName As String
        OSDomain As String
        EmailAddress As String
    End Type
    
    Public Sub SortUserInfo(UserArray As Variant)
        
    Dim i As Integer
    Dim SortFlag As Boolean
    Dim TempUserInfo As UserInformation
        
        SortFlag = False
        While SortFlag = False
            SortFlag = True
            For i = 0 To UBound(UserArray) - 1
                If LCase(UserArray(i).UserName) > LCase(UserArray(i + 1).UserName) Then
                    TempUserInfo = UserArray(i)
                    UserArray(i) = UserArray(i + 1)
                    UserArray(i + 1) = TempUserInfo
                    SortFlag = False
                End If
            Next i
        Wend
    
    End Sub
    My main code is different module calling the SortUserInfo sub

    Code:
    Dim UserInfo() As UserInformation
    
        SortUserInfo (UserInfo)
    This space for rent...

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    The answer is a rather obvious one:
    "Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types"
    Dim is more or less declaring the variable Private, so use the Public keyword and make sure your UDT is located in your module.
    -Excalibur

  3. #3
    Guest

    Don't use

    Your problem is with your variant type in the procedure. If you wish to pass a UDT byref in a procedure, you must declare the type itself:


    Code:
    Public Sub SortUserInfo(UserArray As UserInformation)
    I may be mistaking when I say that you MUST declare the type itself, but I tested it on my computer and I got the same error as you did. When I changed the variable type declaration to UserInformation, I didn't get any error.

    So, I hope that helps.

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