We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Alternatives to array of UDT?

deming
deming asked
on
Medium Priority
275 Views
Last Modified: 2010-04-07
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.


Comment
Watch Question

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Change from a UDT to a Class.

Then store instances of your Class in a Collection.
CERTIFIED EXPERT

Commented:
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?

Author

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?
CERTIFIED EXPERT

Commented:
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:~)



CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.