Home All Groups Group Topic Archive Search About

Creating a collection of a type block... Possible?

Author
13 May 2005 3:17 PM
Patrick Garceau
I want to create a collection of a type block

Public Type NameBlock
    Name as String
    FirstName as string
End Type


can i Create a collection of this type block, so i can use the .add method
and .remove method?
like;

Dim MyNameCol as new Collection of NameBlock


or should i just create an array, like

Dim MyNameVar() as NameBlock



any suggestion?

Thanks again.

Author
13 May 2005 3:43 PM
Ken Halter
Show quote
"Patrick Garceau" <garce***@microbusinfo.com> wrote in message
news:%23Q5vlC9VFHA.1404@TK2MSFTNGP09.phx.gbl...
>I want to create a collection of a type block
>
> Public Type NameBlock
>    Name as String
>    FirstName as string
> End Type
>
>
> can i Create a collection of this type block, so i can use the .add method
> and .remove method?
> like;
>
> Dim MyNameCol as new Collection of NameBlock
>
>
> or should i just create an array, like
>
> Dim MyNameVar() as NameBlock
>

If you want to use UDTs, you're basically limited to an array. You may want
to go through a few of these for some ideas.

Results 1 - 100 of 402 for UDT Collection -dotnet group:*.vb.*. (0.58
seconds)
http://groups.google.co.uk/groups?as_q=UDT+Collection&num=100&scoring=r&hl=en&as_epq=&as_oq=&as_eq=dotnet&as_ugroup=*.vb.*&as_usubject=&as_uauthors=&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=13&as_maxm=5&as_maxy=2005&safe=off

Basically, if you convert that UDT to a class module, you can use a
collection or an array or.... anything you want. Classes don't suffer from
the same restrictions as UDTs do... plus, they're far more flexible.

Converting a User Defined Type to a Class Module
http://www.vbsight.com/UDT_Class.htm

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
Author
13 May 2005 3:44 PM
Mike D Sutton
> I want to create a collection of a type block
<code snipped>
> can i Create a collection of this type block, so i can use the .add method
> and .remove method?
> or should i just create an array

A UDT cannot be coerced into a Variant at runtime and as such cannot be stored in a collection.  You may be able to make it work by
declaring the UDT in a typelib, otherwise just use an array or write your own collection object for that specific UDT.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
13 May 2005 3:45 PM
Jan Hyde
"Patrick Garceau" <garce***@microbusinfo.com>'s wild
thoughts were released on Fri, 13 May 2005 11:17:53 -0400
bearing the following fruit:

>I want to create a collection of a type block
>
>Public Type NameBlock
>    Name as String
>    FirstName as string
>End Type
>

I suggest using classes instead of types.

J

Show quote
>can i Create a collection of this type block, so i can use the .add method
>and .remove method?
>like;
>
>Dim MyNameCol as new Collection of NameBlock
>
>
>or should i just create an array, like
>
>Dim MyNameVar() as NameBlock
>
>
>
>any suggestion?
>
>Thanks again.
>


Jan Hyde (VB MVP)

--
A forger is a man who made a name for himself.  (Henny Youngman)  

[Abolish the TV Licence - http://www.tvlicensing.biz/]

AddThis Social Bookmark Button