Click to See Complete Forum and Search --> : Collections And UDTs


John Holifield
January 7th, 2000, 05:16 PM
Hello,

Can someone please tell me if it is possible to add a User Defined Type to a collection in Visual Basic 5? From what I've read in the Books online, this is possible, but I can't seem to get it to compile correctly. The compiler keeps saying "ByRef Argument Type Mismatch" at the line where I am trying to .Add to the collection.

For example:

private Sub AddTUFEditError(nseverity as Long, nField as Long, strMessage as string)
Dim theError as TUFEditError

theError.Severity = nseverity
theError.FieldNum = nField
theError.ErrorMessage = strMessage

TUFEditErrorCollection.Add theError 'ERR!

End Sub




Please forgive me if this is a stupid question, but I can't figure out how to make this work, and this one detail is holding my project up.

Please if anyone knows of a way around this problem, post the solution or e-mail me.

Thanks,
John Holifield
jdholifield@hotmail.com
jholifield@sungard.com

Bruno
January 9th, 2000, 05:28 PM
No, you cannot do that. You have 2 possible solutions:
1. Instead of collection, use array with your UDT
2. Replace your UDT with a class, e.g.

'------------------------------
' class TUFEditError
Option Explicit
Public Severity As Long
Public FieldNum As Long
Public ErrorMessage As String
'------------------------------

You'll have to add 1 line in your Sub AddTUFEditError:

Dim theError As TUFEditError
Set theError = New TUFEditError ' create instance of the TUFEditError class
theError.Severity = nseverity
theError.FieldNum = nField
theError.ErrorMessage = strMessage

TUFEditErrorCollection.Add theError