2 daihao690 Daihao690 于 2014.09.19 12:07 提问

Visual Basic 6.0精简版,如何在实体类中定义类属性?

我想在类中定义类属性

玩家类代码

'玩家类

'名称
Private Name As String
'性别
Private Sex As SexEnum
'级别
Private Level As Integer
'当前级别分数
Private LevelScore As Integer
'总分
Private SumScore As Integer
'境界
Private PlayerRealm As Realm
'豆豆虫
Private PlayerPeasBug As PeasBug

'属性Get和Set方法
Public Property Get GetName() As String
GetName = Name
End Property
Public Property Let SetName(SetName As String)
Name = SetName
End Property
Public Property Get GetSex() As SexEnum
GetSex = Sex
End Property
Public Property Let SetSex(SetSex As SexEnum)
Sex = SetSex
End Property
Public Property Get GetPlayerRealm() As Realm
GetPlayerRealm = PlayerRealm
End Property
Public Property Let SetPlayerRealm(ByVal SetPlayerRealm As Realm)
PlayerRealm = SetPlayerRealm
End Property

'境界类名称为Realm

'境界名称
Private Name As String
'进入下一境界所需分数
Private NextRealmScore As Integer

'属性Get和Set方法
Public Property Get GetName() As String
GetName = Name
End Property
Public Property Let SetName(SetName As String)
Name = SetName
End Property
Public Property Get GetNextRealmScore() As Integer
GetNextRealmScore = NextRealmScore
End Property
Public Property Let SetNextRealmScore(SetNextRealmScore As Integer)
NextRealmScore = SetNextRealmScore
End Property

我这样写报错

Set Realm = New Realm
Realm.SetName() = "先天"
Player.SetPlayerRealm() = Realm

我想问的是

 '境界
Private PlayerRealm As Realm

    Public Property Get GetPlayerRealm() As Realm
    GetPlayerRealm = PlayerRealm
End Property
Public Property Let SetPlayerRealm(ByVal SetPlayerRealm As Realm)
    PlayerRealm = SetPlayerRealm
End Property

这个该怎么写?

1个回答

fonjames
fonjames   2015.06.20 00:21

都实现了property, 直接赋值跟获取就可以了。

Realm.SetName=" 先天"
Set Player.SetPlayerRealm = Realm

参考MSDN的控件属性

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!