1

我正在尝试实现一些 VB.NET 代码,该代码从 Web 表单中获取信用卡详细信息并将它们传递到支付对象中。我已经为另一个页面上的个人详细信息表单完成了此操作,效果很好。

但是,在此页面上,我收到Too many arguments to Public Sub New()以下行的错误:

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

这是没有任何意义的部分。它需要三个参数,而我要发送三个参数。真的没有更多的信息可以提供。下面是背后的代码和支付类。

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

Payment.aspx.vb我有:

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)
4

2 回答 2

1

你的构造函数应该是:

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

如果问题是其他问题,请提供更多详细信息。

于 2013-10-28T10:36:17.313 回答
0

正如我所怀疑的那样……一些不那么明显但简单的事情。我的网站包含 Payment.aspx,其中当然包含 Payment.aspx.vb 后面的代码和部分支付类。这引起了我在创建对象时所指的付款方式的混淆。

为了解决这个问题,我将 Payment.vb 中的代码复制到了一个名为 Card.vb 的新类中,并在创建对象时将引用更改为:Dim cardDetails As **Card**= New **Card**(Me.CardNumber.Text, Me.CardExpiryMonth.Text, Me.CardExpiryYear.Text)

重建解决方案,错误消失了。

于 2013-10-29T04:35:32.143 回答