我无法让类工作并为这些类传递参数。我已经弄清楚了我自己的其他大部分错误,但有一个错误真的让我烦恼。我得到的错误是“objAttendee”。错误说“没有为参数指定参数”strFirstName“public Sub New(ByVal strFirstName As String,ByVal strLastName As String,ByVal strCourses As String,ByVal intDays As String)”。我完全不确定如何解决这个问题。
任何人都可以帮我解决这个问题吗?
Option Strict On
Public Class Attendee
Dim objAttendee As New Attendee
'class variables
Private _strFirstName As String
Private _strLastName As String
Private _strCourses As String
Private _intDays As Integer
Private _decTotal As Decimal
Private _decCostPerDay As Decimal = 350D
Private _decPreConferenceCost As Decimal = 675D
Sub New(ByVal strFirstName As String, ByVal strLastName As String, ByVal strCourses As String, ByVal intDays As String)
'Contructor
_strFirstName = strFirstName
_strLastName = strLastName
_strCourses = strCourses
_intDays = Convert.ToInt32(intDays)
End Sub
Function ComputeCourseCosts() As Decimal
'Calculates the cost if a pre-conference course is not selected
_decTotal = _intDays * _decCostPerDay
Return _decTotal
End Function
Function ComputePreConferenceCosts() As Decimal
'Calculates the cost if a pre-conference course is selected
_decTotal = _intDays * _decCostPerDay + _decPreConferenceCost
Return _decTotal
End Function
End Class
答案 0 :(得分:0)
“参数未指定参数”.....
Plutonix 告诉您问题的根源:
您在参与者类中声明参加者对象(这没有多大意义)
Public Class Attendee
Dim objAttendee As New Attendee ' <- offending code :P
但该类的构造函数声明如下:
Sub New(ByVal strFirstName As String, ByVal strLastName As String, ByVal strCourses As String, ByVal intDays As String)
你没有没有任何参数的构造函数,如:
Public Sub New() ' No parameter required
' ...
End Sub
您不必创建/声明此类Attendee构造函数的变体,否则,您必须为_strFirstName
定义默认值,_strLastName
,{{ 1}}和_strCourses
!
我认为 ......你有迫切需要测试你的参加者类,并在 中宣布参加者变量 ;;)
不,你应在你的课程之外(例如在你的程序的主要部分中)声明_intDays
并使用适当的参数。
Dim objAttendee As New Attendee(...)