Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a list of objects

Tags:

vba

Hi can I use a variable to create an object. I have an array of several names and for each of those names, I would like to create an object. So I have ("Max", "Tim", "Fred") and would like to loop through that array with the result that I get something similar to doing it manual like this

Dim Max as CmyClass
Dim Tim as CmyClass
Dim Fred as CmyClass

(if that is very much against all good habits of programming, please let me know how to do that properly)

Thanks

like image 805
user1266138 Avatar asked Mar 13 '12 14:03

user1266138


1 Answers

It's not against good programming for as far as I know, but you would need something to store the objects in, which in the case of VBA would be an array or a collection.

something like this

Sub test()
    Dim col As Collection

    Set col = New Collection

    For i = 0 To 4
        Dim Name As Class1
        Set Name = New Class1
        col.Add Name, "test" & i
    Next i
End Sub
like image 105
len Avatar answered Sep 20 '22 07:09

len