Board index » Visual Studio » Declare Array as Collection?

Declare Array as Collection?

Visual Studio4
I am using an array, the elements of which are collection objects. I

am unsure of the best/safest/proper/most advantagous... way to declare

the array. Both methods shown work, but I'm unsure of what

'side-effects' might arise from one or the other.



Should one?



Dim Arry(2) As New Collection

Arry(0).Add <someitem>

'... etc.



Or should one?



Dim Arry(2) as Collection

For Indx=0 to 2

Set Arry(Indx)= New Collection

Next Indx

Arry(0).Add <someitem>

' ... etc.



Or doesn't it matter?



--

Al K

A CDC 1604 was a Univac 1103

made at 501 Park Ave.


-
 

Re:Declare Array as Collection?



"Al K" <noid@sorry.nomail>wrote in message

Quote
I am using an array, the elements of which are collection

objects. I

am unsure of the best/safest/proper/most advantagous... way

to declare

the array. Both methods shown work, but I'm unsure of what

'side-effects' might arise from one or the other.



Should one?



Dim Arry(2) As New Collection

Arry(0).Add <someitem>

'... etc.



One consequence of using the New keyword, is that you can not

test the element for "Nothing". This comparison will always be

false because of implicit instantiation:



If Arry(1) Is Nothing Then





Quote
Or should one?



Dim Arry(2) as Collection

For Indx=0 to 2

Set Arry(Indx)= New Collection

Next Indx

Arry(0).Add <someitem>

' ... etc.



This is my preference -- I prefer to control when object are

created.



Quote
Or doesn't it matter?



It is largely a matter of taste.





-

Re:Declare Array as Collection?

"Al K" <noid@sorry.nomail>wrote

Quote
I am using an array, the elements of which are collection objects. I

am unsure of the:



best>Use Set, and only create them when you need them

safest>Use New, your collections will always be avaliable

proper>Use Set, it gives you better contol over creation/destruction

most advantagous - You decide, based on how you plan to use it.



<g>

HTH

LFS







-

Re:Declare Array as Collection?

Thanks "Grinder",

Although Arry in principle will be 'fully' populated, maybe things

will change and then the test



If Arry(<someindx>) Is Nothing



will be valuable. So Set it is. Thanks.



--

Al K

A CDC 1604 was a Univac 1103

made at 501 Park Ave

.

"Grinder" <grinder@no.spam.maam.com>wrote in message

[SNIP]

Quote
>Dim Arry(2) As New Collection

>Arry(0).Add <someitem>

>'... etc.



One consequence of using the New keyword, is that you can not

test the element for "Nothing". This comparison will always be

false because of implicit instantiation:



If Arry(1) Is Nothing Then

[SNIP]



-