Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default newbie needs help with collections


Hi,

I am having some trouble with collections. I'm trying to pass a
collection to a function to do some work, but whenever I get a compile
error "argument not optional". Everything seems to look ok, I've tried
a lot of variations on this, here is my code:


Code:
--------------------


Dim results As New Collection

' code here to get results

Dim topResults As New Collection

' call get top results function
topResults = getTopResults(results) ' fails here


' top results function
Public Function getTopResults(ByRef list As Collection) As Collection

Dim maxByProgram As Collection
Dim topResults As Collection

maxByProgram = getMaxByProgram(list)

Dim i As Integer
For i = 0 To list.Count
Dim result As Score
Dim Program As String

result = list(i)
Program = Score.Program

Dim max As Integer
max = maxByProgram.Item(Program).Score

If Score.Score = max Then
topResults.Add result
End If
Next i

getTopResults = topResults

End Function

--------------------


Any help on this would be much appreciated.


--
rozner
------------------------------------------------------------------------
rozner's Profile: http://www.excelforum.com/member.php...o&userid=25794
View this thread: http://www.excelforum.com/showthread...hreadid=392006

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default newbie needs help with collections

rozner,

This will only get you started...
'-------------------------
Sub NewsGroupTest()
Dim results As Collection
Dim topResults As Collection

Set results = New Collection
' code here to get results

' call get top results function
Set topResults = getTopResults(results)

Set results = Nothing
Set topResults = Nothing
End Sub
'-------------------------

Jim Cone
San Francisco, USA



"rozner" wrote in
message ...
Hi,
I am having some trouble with collections. I'm trying to pass a
collection to a function to do some work, but whenever I get a compile
error "argument not optional". Everything seems to look ok, I've tried
a lot of variations on this, here is my code:
Code:
--------------------
Dim results As New Collection

' code here to get results

Dim topResults As New Collection

' call get top results function
topResults = getTopResults(results) ' fails here


' top results function
Public Function getTopResults(ByRef list As Collection) As Collection

Dim maxByProgram As Collection
Dim topResults As Collection

maxByProgram = getMaxByProgram(list)

Dim i As Integer
For i = 0 To list.Count
Dim result As Score
Dim Program As String

result = list(i)
Program = Score.Program

Dim max As Integer
max = maxByProgram.Item(Program).Score

If Score.Score = max Then
topResults.Add result
End If
Next i

getTopResults = topResults

End Function

--------------------
Any help on this would be much appreciated.
rozner

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default newbie needs help with collections

Untested--too many functions don't exist for me (getMaxByProgram for example).

But this made it by the error:

Set topResults = getTopResults(results)

Collections are objects. To assign objects, you need to use the Set keyword.

For example:
dim rng as range
set rng = range("a1:B9")

rozner wrote:

Hi,

I am having some trouble with collections. I'm trying to pass a
collection to a function to do some work, but whenever I get a compile
error "argument not optional". Everything seems to look ok, I've tried
a lot of variations on this, here is my code:

Code:
--------------------


Dim results As New Collection

' code here to get results

Dim topResults As New Collection

' call get top results function
topResults = getTopResults(results) ' fails here


' top results function
Public Function getTopResults(ByRef list As Collection) As Collection

Dim maxByProgram As Collection
Dim topResults As Collection

maxByProgram = getMaxByProgram(list)

Dim i As Integer
For i = 0 To list.Count
Dim result As Score
Dim Program As String

result = list(i)
Program = Score.Program

Dim max As Integer
max = maxByProgram.Item(Program).Score

If Score.Score = max Then
topResults.Add result
End If
Next i

getTopResults = topResults

End Function

--------------------

Any help on this would be much appreciated.

--
rozner
------------------------------------------------------------------------
rozner's Profile: http://www.excelforum.com/member.php...o&userid=25794
View this thread: http://www.excelforum.com/showthread...hreadid=392006


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collections of Collections David Morton Excel Programming 6 November 13th 04 01:10 AM
Help with collections ksnapp[_45_] Excel Programming 1 April 7th 04 12:42 AM
Using Collections Kerry[_4_] Excel Programming 1 January 25th 04 04:08 PM
Collections Lookups Dave Curtis[_3_] Excel Programming 1 December 3rd 03 09:15 AM
Comparing Collections Tom Ogilvy Excel Programming 1 September 17th 03 06:15 PM


All times are GMT +1. The time now is 03:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"