Collection of my own type
-
Hi ! Using VB6, in a standard EXE app, I'm trying to add in a collection elements of my own type :
Option Explicit Private m_colMyCol As Collection Private Type MyType lLong As Long iInteger As Integer sString As String End Type Private Sub Form_Load() Dim l_lRec As MyType Set m_colMyCol = New Collection l_lRec.iInteger = 1 l_lRec.lLong = 10 l_lRec.sString = "Hello" m_colMyCol.Add l_lRec MsgBox m_colMyCol.Count End Sub
When I run this sample code, I get this error : 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 I tried to put the type declaration as Public in a module, but I still get the same message. Anyone got an idea what I'm doing wrong ? Thanks ! Jerome -
Hi ! Using VB6, in a standard EXE app, I'm trying to add in a collection elements of my own type :
Option Explicit Private m_colMyCol As Collection Private Type MyType lLong As Long iInteger As Integer sString As String End Type Private Sub Form_Load() Dim l_lRec As MyType Set m_colMyCol = New Collection l_lRec.iInteger = 1 l_lRec.lLong = 10 l_lRec.sString = "Hello" m_colMyCol.Add l_lRec MsgBox m_colMyCol.Count End Sub
When I run this sample code, I get this error : 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 I tried to put the type declaration as Public in a module, but I still get the same message. Anyone got an idea what I'm doing wrong ? Thanks ! JeromeYes, it can't be done. The only way I was able to do this was to Create a simple Class module and store the Class Objects within the Collection. 1.) Create a Class in your App. 2.) Create the Properties Public ID As Long Public intCounter As Integer Public Key As String That's it! Just create new instances of the class and store them in the Collection.:)