-
July 2nd, 2007, 01:36 PM
#1
Is it legal VB to return a collection as a property from a class?
I've created a collection in a class, now want to return it via a property in the class.
The invocation (below) to return the class is giving me "Compile Error Argument not optional"
There are no arguments- why is the compiler complaining?
Code:
Sub CreateLabReport()
Dim filereader As New clsReadTextFile
Dim AllTestNames As New Collection
AllTestNames = filereader.getAllTestNames() ' this line causes error msg
end sub
The AllTestNames collection is defined in another class as follows
Code:
Private colAlltests As New Collection
Property Get getAllTestNames() As Collection
getAllTestNames = colAlltests
End Property
Private Sub Class_Initialize()
testNamesMasterList = "testnames.txt"
Call ReadTestNames
End Sub
Private Sub SeparateTestnames(listofTests As String)
Dim newtest As clsTestDescription
Dim teststr() As String
Dim x, lastTestNum As Integer
Dim testNumber As Long
teststr() = Split(listofTests, vbCrLf)
lastTestNum = UBound(teststr)
testNumber = 1 ' these are arbitrary test numbers
For x = 0 To lastTestNum
'If teststr(x) <> "" Then
If LenB(teststr(x)) <> 0 Then ' don't add to collection, if string is empty
Set newtest = New clsTestDescription
newtest.letTestname = Trim(teststr(x))
newtest.letTestNumber = testNumber ' arbitrary test number
colAlltests.Add newtest
testNumber = testNumber + 1
End If
Next x
End Sub
Last edited by cappy2112; July 2nd, 2007 at 01:39 PM.
-
July 3rd, 2007, 10:13 AM
#2
Re: Is it legal VB to return a collection as a property from a class?
I think you must use the Set directive to assign a collection
Try this:
Code:
Property Get getAllTestNames() As Collection
Set getAllTestNames = colAlltests
End Property
...
Sub CreateLabReport()
Dim filereader As New clsReadTextFile
Dim AllTestNames As Collection
Set AllTestNames = filereader.getAllTestNames() ' this line causes error msg
end sub
Seems to work for me...
-
July 3rd, 2007, 11:23 AM
#3
Re: Is it legal VB to return a collection as a property from a class?
Originally Posted by WoF
I think you must use the Set directive to assign a collection
Try this:
Code:
Property Get getAllTestNames() As Collection
Set getAllTestNames = colAlltests
End Property
...
Sub CreateLabReport()
Dim filereader As New clsReadTextFile
Dim AllTestNames As Collection
Set AllTestNames = filereader.getAllTestNames() ' this line causes error msg
end sub
Seems to work for me...
It works for me too- thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|