我正在尝试实现一些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)
答案 0 :(得分: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
如果问题出在其他方面,请提供更多详情。
答案 1 :(得分: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)
重建解决方案,错误消失了。