how to transfer collection between procedures

  • Thread starter Thread starter Michael Kensy
  • Start date Start date
M

Michael Kensy

Hi,

in OL.2k3 I wrote a sub function to gather different items matching to
conditions. That code is working fine. The problem I can't solve is how to
give back that collection object to the calling main routine.

the code looks like:
***
Function funcFindItems(Arg1As String, Arg2 As MAPIFolder) As Collection
Dim colFoundItems As New Collection

....
colFoundItems.Add objItem
....

If Not IsNothing(colFoundItems) Then Set funcFindItems = colFoundItems

Wayout:
Set colFoundItems = Nothing
Exit Function
***

The problem I have seems to be related to the collection object itself
because colFoundItems gathers all objects I'am looking for but they get
lost at line

Set funcFindItems = colFoundItems

It seems to be necessary to dimension that function as NEW Collection but
it doesn't seem to be possible
 
Hi Michael,
If Not IsNothing(colFoundItems) Then Set funcFindItems =
colFoundItems


replace that line please by:

If Not (colFoundItems Is Nothing) Then Set funcFindItems = colFoundItems

BTW: It´s meaningless to check colFoundItems for Nothing because it´s
declared As New, i.e. even if it´s Nothing: by testing for it the
instance will be created.
 
Hallo Michael,

auch von mir ganz dicke Glueckwuensche zu Deiner Ernennung :-)
Now I continue talking english because of that international newsgroup


Montag, den 04 April 2005 schrieb Michael Bauer:
replace that line please by:
If Not (colFoundItems Is Nothing) Then Set funcFindItems = colFoundItems


sorry I forgot to tell you I wrote a function called IsNothing (because to
get it strict on some other functions like IsEmpty, IsNull and so on doing
exactly the same.

BTW: It´s meaningless to check colFoundItems for Nothing because it´s
declared As New, i.e. even if it´s Nothing: by testing for it the
instance will be created.


the problem is *not* to add items at colFoundItems, thats working fine...
Debugging through that code I can see all contained Items.
The problem is to give back that collection object to the calling function
because I can't dimension a function As *New* Collection ...

The code looks like:
***
Function funcFindItems(some Arguments) as Collection
....
Set funcFindItems = colFoundItems
....
End Function
***
 
Hi Michael,

thanks :-)

You don´t need to declare the function As New (and it isn´t possible).
The problem is to give back that collection object to the calling function
because I can't dimension a function As *New* Collection ...

There is really no problem returning the reference. What do you mean by
"problem", returns your function Nothing, is the returned collection
empty, or do you get an error?
Set funcFindItems = colFoundItems

Because you aren´t showing all your lines, did you check colFoundItems
at that last line if it contains the added items?
 
Hallo Michael,

Montag, den 04 April 2005 schrieb Michael Kensy:
the problem is *not* to add items at colFoundItems, thats working fine...
Debugging through that code I can see all contained Items.
The problem is to give back that collection object to the calling function
because I can't dimension a function As *New* Collection ...


sorry, I think I have been wrong because it is working now. It looks like I
had to restart OL to get it working

OR

my brain hasn't been working on sunday ;-)
 
Back
Top