Alternatives to array of UDT?

What alternatives do you suggest in place of using a dynamic array of UDT ?

My UDT is comprised of non-fixed length strings, double, long, UDT, enums with about 50 fields.  The array must be able to grow and shrink as elements are added and deleted.


demingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Change from a UDT to a Class.

Then store instances of your Class in a Collection.
inthedarkCommented:
Yes idle_mind's suggestion is a good one, but this will only be fast for small numbers of objects. When you have to create or dispose thousands of entries it will be very slow.

The nice thing about UDT is they are very fat, nothing faster,

A quick, easy and fast way to handle thousands of records is to use a an adodb recordset in a disconnected manner.  You can aslo save/restore data to disk in one fast hit. You can do sorts, create index and rapid finds. Delete and addnew records.

Do you want some examples?
demingAuthor Commented:
Hi inthedark, yes, please provide some examples of what you suggest using adodb in a disconnected manner. Does that mean it will only use memory and not write to disk unless I want to?
inthedarkCommented:
Yes don't need a disk or a database, but you can if you want save to a file. (In fast format or xml as you wish.)

' First create your disconnected recordset

Dim RS As ADODB.Recordset
Set RS = New ADODB.Recordset
With RS
    Set .ActiveConnection = Nothing
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic

    ' create some fields
    With .Fields
        .Append "Team", adVarChar, 100
        .Append "Priority", adSmallInt
        .Append "Startdate", adDate
    End With
End With

' create some test data

RS.Open

RS.AddNew
RS("Team") = "Ford"
RS("Priority") = 2
RS("StartDate") = DateValue("3/3/2002")
RS.Update

RS.AddNew
RS("Team") = "Ford"
RS("Priority") = 3
RS("StartDate") = DateValue("3/3/2002")
RS.Update

RS.AddNew
RS("Team") = "McDonalds"
RS("Priority") = 1
RS("StartDate") = DateValue("3/3/2002")
RS.Update

RS.AddNew
RS("Team") = "BBC"
RS("Priority") = 0
RS("StartDate") = DateValue("3/3/2002")
RS.UpdateBatch

' do some filtering (hide records you don't want to see
' or find a specific record/group of records

Debug.Print "START FILTERED RS"
RS.Filter = "[team]='ford' and [priority]=3"
RS.MoveFirst
Do While Not RS.EOF
 
    Debug.Print RS("team") & " " & RS("priority")
    RS.MoveNext
Loop

' clear the filter

Debug.Print "CLEAR FILTERED RS"

RS.Filter = ""
RS.MoveFirst
Do While Not RS.EOF
 
    Debug.Print RS("team") & " " & RS("priority")
    RS.MoveNext
Loop

msgbox "Now look at debug window"

You can also use sort which can make filtering a lot faster.

RS.Sort = "Priortity"

' You can dynamicall add/delete records.

RS.Delete

Hope this helps:~)



inthedarkCommented:
PS here is a good link which shows how to load and save the recordset safely as there were some problems in some circumstances.

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B317913

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.