我正在尝试实现一些 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)