Click to See Complete Forum and Search --> : Collections


Goldman Asaf
01-23-2001, 09:19 AM
I am using a lot of Collection Objects in VB6.

I can't find how to do it in VB.NET.

Can any one give me an example ?

Thanks,
Asaf

Patrick Steele
01-23-2001, 09:38 AM
In article <3a6d916f@news.devx.com>, asafgo@hotmail.com says...
> I am using a lot of Collection Objects in VB6.
>
> I can't find how to do it in VB.NET.

See the System.Collections namespace.

> Can any one give me an example ?

Dim oList As ArrayList = new ArrayList()
oList.Add("Hello")
oList.Add("World")

For each oItem in oList
Console.WriteLine("{0}", oItem.ToString())
next

Note: imports, namespaces and other "stuff" removed for brevity.

--
Patrick Steele
(psteele@ipdsolution.com)
Lead Software Architect

Goldman Asaf
01-23-2001, 09:52 AM
Thanks,
But I want to add objects.

"Patrick Steele" <psteele@ipdsolution.com_> wrote in message
news:MPG.14d76184b676dceb989681@news.devx.com...
> In article <3a6d916f@news.devx.com>, asafgo@hotmail.com says...
> > I am using a lot of Collection Objects in VB6.
> >
> > I can't find how to do it in VB.NET.
>
> See the System.Collections namespace.
>
> > Can any one give me an example ?
>
> Dim oList As ArrayList = new ArrayList()
> oList.Add("Hello")
> oList.Add("World")
>
> For each oItem in oList
> Console.WriteLine("{0}", oItem.ToString())
> next
>
> Note: imports, namespaces and other "stuff" removed for brevity.
>
> --
> Patrick Steele
> (psteele@ipdsolution.com)
> Lead Software Architect

Patrick Steele
01-23-2001, 10:09 AM
In article <3a6d991f@news.devx.com>, asafgo@hotmail.com says...
> Thanks,
> But I want to add objects.

The Add method of the ArrayList() class accepts any .NET object. The
signature is:

Overridable Public Function Add(ByVal value As Object) As Integer

--
Patrick Steele
(psteele@ipdsolution.com)
Lead Software Architect

c2i - Richard Clark
01-23-2001, 12:52 PM
You have 3 articles about it in c2i.fr.
Find them at : http://www.c2i.fr/lstsources.asp?IDCate=16
In the last one (about performances at
http://www.c2i.fr/code.asp?IDCode=1062), you'll have code to download.
Beware : text in french
--
Richard Clark - rc@c2i.fr
______________________________________________
BONNE ANNEE
----------------------------------------------
http://www.c2i.fr - Le portail francophone
Visual Basic,VB.NET,ASP, ASP.NET
+ de 500 aides disponibles (20/01)
______________________________________________
"Goldman Asaf" <asafgo@hotmail.com> wrote in message
news:3a6d916f@news.devx.com...
> I am using a lot of Collection Objects in VB6.
>
> I can't find how to do it in VB.NET.
>
> Can any one give me an example ?
>
> Thanks,
> Asaf
>
>

Per Hultqvist
02-01-2001, 08:27 AM
> > Can any one give me an example ?
>
> Dim oList As ArrayList = new ArrayList()
> oList.Add("Hello")
> oList.Add("World")
>
> For each oItem in oList
> Console.WriteLine("{0}", oItem.ToString())
> next
>
> Note: imports, namespaces and other "stuff" removed for brevity.
>
> --
> Patrick Steele

I ran into a problem related to this yesterday. I wanted to create a set of
collectionclasses (you know, one cServers class containing a collection of
cServer-objects) and make it enumerable, to use it with the For-Each syntax
(New_Enum in VB6).

I tried several things (Implement IEnumerable, Inherit some class (don't
remember the name), create a public GetEnumerator-function and expose the
collections GetEnumerator-function, ...) but nothing was working. How do I
make the For-Each syntax work for my own classes? Anyone have a code-sample?

Any help appreciated...

--
/Per
______________________________
Per Hultqvist, Hogia Ekonomi AB
MCP - Microsoft Certified Professional

Patrick Steele
02-01-2001, 09:08 AM
In article <3a796518$1@news.devx.com>, per.hultqvist@hogia.se says...
> I wanted to create a set of
> collectionclasses (you know, one cServers class containing a collection of
> cServer-objects) and make it enumerable, to use it with the For-Each syntax
> (New_Enum in VB6).

Inherit from one of the Systems.Collections.Bases classes:

Module Module1

Sub Main()
Dim oEmp1 As Employee = New Employee("Bill", "Gates", 35)
Dim oEmp2 As Employee = New Employee("Steve", "Ballmer", 37)
Dim oEmp3 As Employee = New Employee("Bob", "Butler", 33)
Dim oWF As WorkForce = New WorkForce()
Dim oEmpl As Employee
Dim iIndex As Integer

oWF.Add(oEmp1)
oWF.Add(oEmp2)
oWF.Add(oEmp3)

For Each oEmpl In oWF
Console.WriteLine("{0} {1} is {2} years old!", _
oEmpl.FirstName, _
oEmpl.LastName, _
oEmpl.Age.ToString())
Next
Console.WriteLine("")

For iIndex = 0 To oWF.Count - 1
oEmpl = oWF.Item(iindex)
Console.WriteLine("{0} {1} is {2} years old!", _
oEmpl.FirstName, _
oEmpl.LastName, _
oEmpl.Age.ToString())
Next

End Sub

End Module

Public Class Employee
Public FirstName As String
Public LastName As String
Public Age As Short

Public Sub New(ByVal sFirst As String, ByVal sLast As String, _
ByVal iAge As Short)
FirstName = sFirst
LastName = sLast
Age = iAge
End Sub

End Class

Public Class WorkForce
Inherits System.Collections.Bases.TypedCollectionBase

Public Function Add(ByVal oEmp As Employee) As Integer
Return MyBase.InnerList.Add(oEmp)
End Function

Public Sub Remove(ByVal oEmp As Employee)
MyBase.InnerList.Remove(oEmp)
End Sub

Public Function Item(ByVal iIdx As Integer) As Employee
Return CType(MyBase.InnerList.Item(iidx), Employee)
End Function

End Class

--
Patrick Steele
(psteele@ipdsolution.com)
Lead Software Architect

Bob Butler
02-01-2001, 09:37 AM
"Patrick Steele" <psteele@ipdsolution.com_> wrote in message
news:MPG.14e337d6c2ec570b98969b@news.devx.com...
> In article <3a796518$1@news.devx.com>, per.hultqvist@hogia.se says...
> > I wanted to create a set of
> > collectionclasses (you know, one cServers class containing a collection
of
> > cServer-objects) and make it enumerable, to use it with the For-Each
syntax
> > (New_Enum in VB6).
>
> Inherit from one of the Systems.Collections.Bases classes:
>
> Module Module1
>
> Sub Main()
> Dim oEmp1 As Employee = New Employee("Bill", "Gates", 35)
> Dim oEmp2 As Employee = New Employee("Steve", "Ballmer", 37)
> Dim oEmp3 As Employee = New Employee("Bob", "Butler", 33)

I'm not sure I like being put in that grouping <g>

Patrick Steele
02-01-2001, 09:52 AM
In article <3a79743f$1@news.devx.com>, butlerbob@earthlink.net says...
>
> > Dim oEmp3 As Employee = New Employee("Bob", "Butler", 33)
>
> I'm not sure I like being put in that grouping <g>

I was wondering how long it would take you to notice that! :)

I was thinking of changing the sample code to you, Karl and Dan
Barclay...

I assume then, that I'm not offending you with the age? :)

--
Patrick Steele
(psteele@ipdsolution.com)
Lead Software Architect

Bob Butler
02-01-2001, 10:08 AM
"Patrick Steele" <psteele@ipdsolution.com_> wrote in message
news:MPG.14e34228193ca30298969c@news.devx.com...
> In article <3a79743f$1@news.devx.com>, butlerbob@earthlink.net says...
> >
> > > Dim oEmp3 As Employee = New Employee("Bob", "Butler", 33)
> >
> > I'm not sure I like being put in that grouping <g>
>
> I was wondering how long it would take you to notice that! :)
>
> I was thinking of changing the sample code to you, Karl and Dan
> Barclay...
>
> I assume then, that I'm not offending you with the age? :)

Actually, I hadn't read that closely to see what the number was but I don't
see how 33 could be offensive (expecially since I passed that already). Had
you put 12 I might take it the wrong way <g> (and no offense meant to
anybody reading this who happens to be 12)

Andreas Finger
12-05-2001, 10:38 AM
There are a lot of different Collections in VB.NET. You can find they
under System.Collections.

I need instead of the VB6-Collection the Arraylist. The handling is more
or less the same.

Dim col as New System.Collections.ArrayList()




Goldman Asaf wrote:

> I am using a lot of Collection Objects in VB6.
>
> I can't find how to do it in VB.NET.
>
> Can any one give me an example ?
>
> Thanks,
> Asaf
>
>
>