Hello again Michael
how about declaring another user defined type
that will hold your values (create a structure
to hold the array variables)
for example
Private Type udtArrayStructure
myString as String
myInt as Integer
End Type
now create the user defined type you originally required
within the new udt declare an array of type udtArrayStructure
and additional variables
Private Type OriginalUDT
strString as string
intValue As Integer
udtArray() as udtArrayStructure 'create an array of the above type
End Type
all that is left to do now is to create a variable of type OriginalUDT
and you will have the complete structure you required
Private m_DataStructure as OriginalUDT
you should now be able to set the individual contents
of the udtArray as you require
If you know the number of elements then insert them or just
ReDim [Preserve] as you go
each array index value can be set like this
m_udtDataStructure.udtArray(index).myString = "SomeString"
m_udtDataStructure.udtArray(index).myInt = intNumber
hope this helps
Nigel
here is some code that I created in VB
cut and paste it into a new project to try it
Private Type udtArrayStructure
strString As String
intNumber As Integer
End Type
Private Type udtOriginal
strValue As String
intValue As Integer
udtArray() As udtArrayStructure
End Type
'now create a variable to hold the structure or type
Private m_udtDataStructure As udtOriginal
Private Sub Form_Load()
Dim index as integer
index = 5
ReDim Preserve m_udtDataStructure.udtArray(Index)
With m_udtDataStructure
.intValue = 5
.strValue = "Hello"
.udtArray(Index).intNumber = 99
.udtArray(Index).strString = "array string"
End With
MsgBox "Data Structure Integer Value Is " & m_udtDataStructure.intValue &
vbCrLf & _
"Data Structure String Value Is " & m_udtDataStructure.strValue &
vbCrLf & _
"Data Structure Array Integer Is " &
m_udtDataStructure.udtArray(Index).intNumber & vbCrLf & _
"Data Structure Array string Is " &
m_udtDataStructure.udtArray(Index).strString
End Sub
> -----Original Message-----
> From: Michael Findlay [SMTP:michaelgfindlay@h...]
> Sent: Tuesday, August 21, 2001 4:31 PM
> To: professional vb
> Subject: [pro_vb] Storing user-defined types in a Data Structure
>
> Hi,
>
> I'm looking at storing a user-defined type into a Data Structure. The
> type contains a string, an integer and a user-defined 2-D array made up of
>
> a string and an integer.
>
> The use of a PropertyBag would enable me to store the string and integer
> but the problem arises when I need to store the array. I don't really
> want to have to store each element of the array separately into the Data
> Structure.
>
> I need to be able to search on the initial string but other than that I
> just want to be able to read and write the other information. Is there
> any structure available that would allow me to store this defined type?
>
> Cheers
> Michael