1

I am trying to implement some VB.NET code that takes the credit card details from a web form and passes them into the payment object. I've done this for the personal details form on another page, which worked fine.

However, on this page I am getting the Too many arguments to Public Sub New() error for the following line:

Dim cardDetails As Payment = New Payment(Me.CardNumber.Text, Me.CardExpiryMonth.Text, Me.CardExpiryYear.Text)

This is the part that doesn't make any sense. It requires three arguments, and I'm sending it three arguments. There really isn't much more information to give. The below is both the code behind and the payment class.

In Payment.vb:

Imports Microsoft.VisualBasic
Public Class Payment
'declare variables, private
Private cardNo As String
Private expiryMth As String
Private expiryYr As String

''get and set for each variable
Private Property cardNumber() As String
    Get
        Return cardNo
    End Get
    Set(value As String)
        cardNo = value
    End Set
End Property
Private Property expiryMonth() As String
    Get
        Return expiryMth
    End Get
    Set(value As String)
        expiryMth = value
    End Set
End Property
Private Property expiryYear() As String
    Get
        Return expiryYr
    End Get
    Set(value As String)
        expiryYr = value
    End Set
End Property

'no argument constructor
Public Sub New()
End Sub

''sub methods/functions do stuff and return values
Public Overrides Function ToString() As String
    Return cardNo
End Function
Public Sub New(ByVal cardNumber As String, ByVal expiryMonth As String, ByVal expiryYear As String)
End Sub
End Class

And in Payment.aspx.vb I have:

Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
'add the card details from the form to the object.
Dim cardDetails As Payment = New Payment(Me.CardNumber.Text, Me.CardExpiryMonth.Text, Me.CardExpiryYear.Text)
1
  • Thanks Markus, unfortunately that didn't solve the issue. The original post has been edited to add as much information as I have. Commented Oct 28, 2013 at 11:10

2 Answers 2

1

Your constructor should be:

Public Sub New(ByVal cardNumber As String, ByVal expiryMonth As String, ByVal expiryYear As String)
    Me.cardNumber = cardNumber
    Me.expiryMonth = expiryMonth
    Me.expiryYear = expiryYear
End Sub

If the problem is something else, please provide some more details.

Sign up to request clarification or add additional context in comments.

Comments

0

As I suspected... something not so obvious but simple. My site contains Payment.aspx which of course contains code behind Payment.aspx.vb with a Partial Payment Class. This was causing confusion over which Payment I was referring to when creating the object.

To fix I copied my code from Payment.vb into a new Class called Card.vb and changed the reference when creating the object to: Dim cardDetails As **Card**= New **Card**(Me.CardNumber.Text, Me.CardExpiryMonth.Text, Me.CardExpiryYear.Text)

Rebuilt the solution and the error is gone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.