问题描述
- 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 RealmRealm.SetName() = ""先天""Player.SetPlayerRealm() = Realm
我想问的是
'境界Private PlayerRealm As Realm Public Property Get GetPlayerRealm() As Realm GetPlayerRealm = PlayerRealmEnd PropertyPublic Property Let SetPlayerRealm(ByVal SetPlayerRealm As Realm) PlayerRealm = SetPlayerRealmEnd Property
这个该怎么写?
解决方案
都实现了property 直接赋值跟获取就可以了。
Realm.SetName="" 先天""
Set Player.SetPlayerRealm = Realm
参考MSDN的控件属性