Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Pass A Collection To A FUNCTION ??? (Access 2000) Sample Code

Status
Not open for further replies.

MarkDicken

IS-IT--Management
Jun 5, 2000
55
CH
Hi All,

I am trying to Pass A Collection To A FUNCTION ??? (Access 2000)

I have a Class called BO (for Business Objects)

Within BO I have a Function called ShowCollection

Public Sub showcollection(colCollection As Collection)
MsgBox "colCollection(2)=" & colCollection(2)
End Sub

I've tries a whole number of ways and its not working?

The calling code is :-

Dim oCollection As New Collection
oCollection.add "aaa"
oCollection.add "BBB"
oCollection.add "CCC"

Dim oBO As New BO
oBO.showcollection(oBO)

Any IDEAS ???
Many Thanks In Advance ...

Regards

Mark Dicken
England, UK
(Currently Working in Saudi Arabia)
 
Okay what is the function suppose to do and how does it relate to the Collection?

If I take a peek in your Windows, to fix a problem, does that make me a "Peeping Tom"? Hmmmmmmmmmm
 
Mark:
The faster way is: To make your collection public, so you don't have any need to pass it to any function, since you can have access to it from any where.
But if what you want is to know HOW to pass collections to functions the way to do is as follow:

Private sub Any()
Dim oCollection as New collection

oCollection.add "aaa"
oCollection.add "BBB"
oCollection.add "CCC"

Call showcollection
End sub


Public Sub showcollection(colCollection As [b[Variant[/b])
MsgBox "colCollection(2)=" & colCollection(2)
End Sub

Just a note about it:
You should use a collection if
1. You don't know in advance how many items the collection may have.
2. Items stored in collections are Object Type
3. Items in your collection have different data types

if you DO NOT have one of those reasons i suggest you to use Arrays.

If you DO have at least one be aware of:
1. all items in your collection are Variant Type
2. if objects in collection are different types, you CAN NOT treat them in the same way because your code might render in Error.

Good Luck

Estuardo
 
Is this a typo in posting, or could this be the problem
Code:
Dim oCollection As New Collection
oCollection.add "aaa"
oCollection.add "BBB"
oCollection.add "CCC"

Dim oBO As New BO
oBO.showcollection(
oBO
Code:
)
Should it not be
Code:
oBO.showcollection(
oCollection
Code:
)

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion,

Yes it is supposed to be:-

oBO.showcollection(oCollection)

Well done on picking up the error

I'm basically trying to use MS Access in a DOT NET OO sort of way... ANY IDEAS ??? (other than using a global Collection)

EstuardoSierra,

Thanks for the Suggestion, your suggestion is good and I may end up having to use it, currently I am passing ARRAYS but I really would like to pass a COLLECTION... After Checking TECHNET all I could find was info on passing ARRAYS only - ANY IDEAS ANYONE ???

I am surprised that its not been asked before...???

Many Thanks In Advance...

Regards

Mark Dicken
 
There is no reason that you cannot pass a collection as a parameter to a method of a class.

The following code works fine. (I added a quick ShowCollection method to the clsMeeting class to test it)
Code:
Public Sub ShowCollection(colCollection As Collection)
     MsgBox "colCollection(2)=" & colCollection(2)
End Sub
and from the main form dropped in the following code:
Code:
Dim oCollection As New Collection
oCollection.Add "aaa"
oCollection.Add "BBB"
oCollection.Add "CCC"
Set lCls_NewMeeting = New clsMeeting
lCls_NewMeeting.ShowCollection oCollection
If you're encountering some errors, then something else is in play. It may be that we'll need to see the pertinent code to see what else may be affecting the problem.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top