1

This is my first time reaching out for help. I've tried searching but can't seem to find anything that matches my situation.

I have created 2 class modules: Match and MatchResultSet. MatchResultSet has the following properties and methods:

Public NoMatches As Integer
Public NoRounds As Integer
Private Matches() As Match

Public Function GetMatch(ByVal matchNumber As Integer) As Match
    If matchNumber <= NoMatches Then
        Set GetMatch = Matches(matchNumber)
    Else
        Set GetMatch = Nothing
    End If
End Function
Public Sub SetMatch(ByRef aMatch As Match, ByVal matchNumber As Integer)
    MsgBox ("A")
    If matchNumber <= NoMatches Then
    MsgBox ("B")
        Matches(matchNumber) = aMatch
    End If
End Sub

I tried to create a clone method for MatchResultSet that also needs to take a copy of the array of Match objects. However I get the error 438 "Object doesn't support this property or method" on the indicated line:

Public Function Clone() As MatchResultSet
    Dim newMRS As MatchResultSet
    Set newMRS = New MatchResultSet

    newMRS.NoMatches = Me.NoMatches
    newMRS.NoRounds = Me.NoRounds
    For i = 1 To Me.NoMatches
        Set newMatch = Me.GetMatch(i).Clone
        Call newMRS.SetMatch((newMatch), i) '<=== error 438 here
    Next i
    Set Clone = newMRS
End Function

Can anyone help? From what I can tell, I'm calling the Sub with the same parameter class as I defined in my class module.

Community
  • 1
  • 1
  • That would be a duplicate of either [VB6 pass by value and pass by reference](http://stackoverflow.com/a/10262247/11683) or [VBA Adding a class to a collection](http://stackoverflow.com/q/6331106/11683) (remove the parentheses around `newMatch`). – GSerg May 07 '17 at 18:30
  • Thanks! Removing the parentheses to `Call newMRS.SetMatch(newMatch, i)` results in a argument type mismatch error, since then I guess it is trying to pass by value? Also, I have two arguments in my sub, so not sure how to call it without any parentheses, such as in the question you posted. Any ideas? – Uri Schlafrig May 07 '17 at 18:50
  • 1
    Please learn to debug your code. Did you put `option explicit` on top? Did you declare `newMatch`, and as what? – GSerg May 07 '17 at 19:29
  • 2
    In your editor go to Tools > Options > General. In the 'Error Trapping' section, select 'Break in Class Module'. I am almost willing to bet that you error is happening within the class module, and not within the call to the function. This will help you determine *what* it is trying to do when it encounters the error. Also, the use of Call is outdated. Your code should be something like `newMRS.SetMatch newMatch, i`. If you are encountering an error without parentheses then something is wrong with your object, or the expected input of the function you are calling. – Brandon Barney May 08 '17 at 12:21
  • 1
    Thanks @GSerg, the problem was indeed that I hadn't declared `newMatch` as an object, hence I got the error without the parentheses. I didn't know about `option explicit` - newbie :) – Uri Schlafrig May 08 '17 at 19:07
  • @BrandonBarney thanks for the tip! I couldn't understand why it wouldn't break in the right place ... – Uri Schlafrig May 08 '17 at 19:30

0 Answers0