Problems returning Collection object

  • Thread starter Thread starter McManCSU
  • Start date Start date
M

McManCSU

I get this error:
Compile error

Argument not optional

when i try to return a collection like this:

For i = 1 To assyNums.count
For j = 1 To assyNums.Item(i).getBOM.count
partnum = assyNums.Item(i).getBOM.Item(j)
occur = numOccurances(partnum)
numOccur.Add (occur)
Next j
.......

(BOMParts is an obj variable and is already initialized)
Public Function getBOM() As Collection
getBOM = BOMparts
End Function


I have tried the simple way where I make a temporary collection an
assign it to what ".getBOM()" returns but same error. Any help
 
M,

It is difficult to understand what you are trying to do.
Please show your variable declarations and describe
what the code is supposed to do.

Jim Cone
San Francisco, USA


"McManCSU"
<[email protected]>
wrote in message

I get this error:
Compile error

Argument not optional

when i try to return a collection like this:

For i = 1 To assyNums.count
For j = 1 To assyNums.Item(i).getBOM.count
partnum = assyNums.Item(i).getBOM.Item(j)
occur = numOccurances(partnum)
numOccur.Add (occur)
Next j
.......

(BOMParts is an obj variable and is already initialized)
Public Function getBOM() As Collection
getBOM = BOMparts
End Function


I have tried the simple way where I make a temporary collection and
assign it to what ".getBOM()" returns but same error. Any help?
 
All I am trying to do is step through a collection which I have in a
object. So I want is to do a 'get function' to get the collection
store it into a temp variable, and then do a "for each... " But fo
some reason if gives that error and points to where I assign tempBO
the collection.


Code
-------------------
Private Sub setupTFIDF()
Dim partnum As String
Dim occur As Integer
Dim numOccur As New Collection
Dim tempBOM As New Collection
Dim assy As New Assembly
Dim comp As New Component

For Each assy In assyNums
tempBOM = assy.getBOM()
For Each comp In tempBOM
partnum = comp.getAssy()
occur = numOccurances(partnum)
numOccur.Add (occur)
Next comp
'Calc TFIDF by sending number of boards and occurance list
assy.determineTFIDF numBoards, numOccur
Next assy
End Su
-------------------


and using this "Assembly" object:


Code
-------------------
Private BOMparts As New Collection
.......
.......
Public Function getBOM() As Collection
getBOM = BOMparts
End Functio
 
Ok, i narrowed it down:

Dim x As New Collection
Dim y As New Collection
x = y

it errors with that same error on 'x=y'

why and how can i fix it
 
M,

You may want to review:
Don't Use The New Keyword In A Dim Statement
http://www.cpearson.com/excel/variables.htm

The following doesn't throw an error,
but how you would use it is a puzzle to me.
'-------------------
Dim x As New Collection
Dim y As New Collection
Set x = y

'Do stuff

Set x = Nothing
Set y = Nothing
'------------------
Jim Cone
San Francisco, USA


"McManCSU"
<[email protected]>
wrote in message

Ok, i narrowed it down:

Dim x As New Collection
Dim y As New Collection
x = y
it errors with that same error on 'x=y'
why and how can i fix it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top