[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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.


0
deming
Asked:
deming
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Change from a UDT to a Class.

Then store instances of your Class in a Collection.
0
 
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?
0
 
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?
0
 
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:~)



0
 
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
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now