| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2506 人关注过本帖
标题:vb6 错误提示,编译错误。相同属性的属性过程定义不一致,或属性过程中包含 ...
只看楼主 加入收藏
smx_006
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-2-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
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
搜索更多相关主题的帖子: 数学 语文 
2016-02-05 23:26
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
第一个可以用简单的 结构,不需要使用类。

结构:有组织的数据。
类:有组织的数据+数据处理的方法。

好吧,按你的代码去弄,试了一回, 想明白了,你带参数引用,根本不能使用类属性,而应该使用 类方法。
你的错误就出在这。

授人于鱼,不如授人于渔
早已停用QQ了
2016-02-06 09:45
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 

Option Explicit

Private Type score
    name As String
    Value As Single
End Type

Dim stu_score(1 To 9) As score

Public Function scoreR(ByVal strname As String) As Single
Dim i As Long
For i = 1 To 9
    If stu_score(i).name = strname Then
        Exit For
    End If
Next i
If i > 9 Then
    MsgBox "属性" & strname & "不存在!", vbCritical
Else
    scoreR = stu_score(i).Value
End If

End Function

Public Function scoreS(ByVal strname As String, ByVal vdate As Single)
Dim i As Long
For i = 1 To 9
    If stu_score(i).name = strname Then
        Exit For
    End If
Next i
If i > 9 Then
    MsgBox "属性" & strname & "不存在!", vbCritical
Else
    stu_score(i).Value = vdate
End If

End Function


Private Sub Class_Initialize()
      stu_score(1).name = "语文"
      stu_score(2).name = "数学"
      stu_score(3).name = "英语"
      stu_score(4).name = "政治"
      stu_score(5).name = "历史"
      stu_score(6).name = "生物"
      stu_score(7).name = "物理"
      stu_score(8).name = "化学"
      stu_score(9).name = "地理"
End Sub
 
-------------
m.scoreS "语文", 50
Print m.scoreR("语文")

授人于鱼,不如授人于渔
早已停用QQ了
2016-02-06 09:51
快速回复:vb6 错误提示,编译错误。相同属性的属性过程定义不一致,或属性过程中 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040791 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved