|
-
Oct 19th, 2000, 09:10 AM
#1
Thread Starter
Fanatic Member
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)
-
Oct 19th, 2000, 12:01 PM
#2
Fanatic Member
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.
-
Oct 19th, 2000, 12:08 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|