Wrong number of arguments to constructor for class: <class name>

You supplied the wrong number of arguments for a class constructor in one of the following statements:

  • A declaration of the form:

    Dim X As New ClassName

    For example:

    Class MyClass
       Sub New(A As Integer, B As String)
          ' ...
       End Sub
    End Class
    Dim ObjRef As New MyClass(4, "Alex", "Jones")  ' Illegal because 
                                                   ' MyClass's Sub New takes
                                                   ' only two arguments
    Dim ObjRef As New MyClass(4, "Alex Jones")     ' Legal
    
  • A Set statement of the form:

    Set X = New ClassName

  • A declaration of a derived class when the arguments that the derived class's constructor requires are different from the ones that the base class's constructor requires. In this case, constructor arguments for the base class must be specified after the BaseClassName clause in the Sub New declaration, as in the following example:
    Class BaseClass
       Sub New(X As Integer)
          ' ...
       End Sub
    End Class
    Class DerivedClass As BaseClass
      Sub New(Y As String, X As Integer), BaseClass(X%, Y)  ' Illegal
      Sub New(Y As String, X As Integer), BaseClass(X)	     ' Legal
         ' ...
      End Sub
    End Class

Supply the correct number of arguments to the constructor.