vb6 错误提示,编译错误。相同属性的属性过程定义不一致,或属性过程中包含可选参...
我本想自己定义一个对象,存储学生的成绩的,想要的形式如下chengji = stu.score("数学")
stu.score("数学")=80,这是最理性的情况了。
我写的代码如下,请高手指教。错在了那里。
score类:
Option Explicit
Public name As String
Public value As Single
stu_score类:
Option Explicit
Private stu_score(1 To 9) As score
Private Sub Class_Initialize()
Set stu_score(1) = New score
stu_score(1).name = "语文"
Set stu_score(2) = New score
stu_score(2).name = "数学"
Set stu_score(3) = New score
stu_score(3).name = "英语"
Set stu_score(4) = New score
stu_score(4).name = "政治"
Set stu_score(5) = New score
stu_score(5).name = "历史"
Set stu_score(6) = New score
stu_score(6).name = "生物"
Set stu_score(7) = New score
stu_score(7).name = "物理"
Set stu_score(8) = New score
stu_score(8).name = "化学"
Set stu_score(9) = New score
stu_score(9).name = "地理"
End Sub
Public Property Let someitems(ByVal strname As String, ByVal strvalue As Single)
Dim i, doordog As Integer
doordog = 0
For i = 1 To 9
If stu_score(i).name = CStr(strname) Then
doordog = 1
Exit For
End If
Next
If doordog = 1 Then
stu_score(i).value = strvalue
End If
If doordog = 0 Then
MsgBox "属性" & strname & "不存在!", vbCritical
End If
End Property
Public Property Get someitems(ByVal strname As String) As score
Dim i, doordog As Integer
doordog = 0
For i = 1 To 9
If stu_score(i).name = CStr(strname) Then
doordog = 1
Exit For
End If
Next
If doordog = 1 Then
Set someitems = stu_score(i)
End If
If doordog = 0 Then
MsgBox "属性" & strname & "不存在!", vbCritical
End If
End Property