VBA: Storing User Defined Types in A List

Miscellaneous Forums/General Discussion/VBA: Storing User Defined Types in A List

Hi,

I'm trying to get my VBA knowledge up to speed with my BlitzMax knowledge, and although I've found how to define a custom type, I don't know how I would store them in a list like I could in BlitzMax. Hold on, I'll give an example.

Say I've got a user defined type, TPerson, which I've defined in Declarations. I know that I can allocate a new variable the type TPerson using...

Dim newPerson As TPerson


However, say I had a form with a button on saying "Add Person", and evertime it is clicked, an input box asks for the name of the person and makes a new type instance. How would I be able to store all these TPerson type instances, without me knowing how many there are going to be, and so I could loop through them to implement a search feature etc. in VBA?

I know it's a bit off-topic but I can't find anything on Google - I don't think I'm using the correct VBA terminology... Anybody know anything about this? Thanks in advance,


Seb

I'm a VB6 guy, so this may not work in VBA.

1 - use an array, check the redim preserve command for how to expand it at will.

2 - use the collection class (although this might not work with a User Defined Type, if tperson is actually a class then it should work)
http://support.microsoft.com/kb/198465

I'm also not a vba guy but you SHOULD be able to do what he said...

Type Blah
  ID as integer
  Name as string
End Type

Dim Blahs as new Collection
Dim tblah as new blah

for t = 1 to 5
  tblah.id = t
  tblah.name = cstr(t) & "Name"

  Blahs.Add tblah
next


That's off the absolute top of my head, but I think that should give an idea anyway.

That works brilliantly - thanks to both of you!