Dim iID As Long
Dim iName As String
Dim iSex As enSex
Dim iAge As Integer
Dim iAddress As String
Public Property Get ID() As Long
ID = iID
End Property
Public Property Let ID(ByVal vNewValue As Long)
iID = vNewValue
End Property
Public Property Get Name() As String
Name = iName
End Property
Public Property Let Name(ByVal vNewValue As String)
iName = vNewValue
End Property
Public Property Get Sex() As enSex
Sex = iSex
End Property
Public Property Let Sex(ByVal vNewValue As enSex)
iSex = vNewValue
End Property
Public Property Get Address() As String
Address = iAddress
End Property
Public Property Let Address(ByVal vNewValue As String)
iAddress = vNewValue
End Property
Public Property Get Age() As Integer
Age = iAge
End Property
Public Property Let Age(ByVal vNewValue As Integer)
iAge = vNewValue
End Property 作者:
Nothing 时间: 2005-8-25 20:38
CStudents类模块
Option Explicit
Private mcolStudents As New Collection
Dim intNum As Integer
Dim intPosition As Long
Dim iStudent As CStudent
Public Function Add(ByVal Name As String) As CStudent
Dim Student As New CStudent
With Student
'为学生产生一个唯一的 ID。
intNum = intNum + 1
.ID = intNum
.Name = Name
'将 CStudent 对象引用添加到集合中,
'用 ID 属性作为键。
mcolStudents.Add Student, "K" & .ID
End With
'为新的 CStudent 返回一个引用。
Set Add = Student
Set iStudent = Student
End Function
Public Function Count() As Long
Count = mcolStudents.Count
End Function
'删除其中的一个学生记录
Public Sub Delete(ByVal Index As Long)
mcolStudents.Remove "K" & Index
End Sub
'CStudents 集合类的方法。
Public Function Item(ByVal Index As Variant) As CStudent
'On Error Resume Next
Set Item = mcolStudents.Item("K" & Index)
End Function
'清除所有学生记录
Public Sub Clear()
Set mcolStudents = Nothing
Set mcolStudents = New Collection
intNum = 0
End Sub
Public Property Get Position() As Long
Position = intPosition
End Property
Public Property Let Position(ByVal vNewValue As Long)
If vNewValue < 1 Or vNewValue > mcolStudents.Count Then
Exit Property
End If
intPosition = vNewValue
Set iStudent = mcolStudents.Item("K" & intPosition)
End Property
Public Sub Move(Index As Long)
If Index < 1 Or Index > mcolStudents.Count Then
Exit Sub
End If
Set iStudent = mcolStudents.Item("K" & Index)
intPosition = Index
End Sub
Public Property Get SelectStudent() As CStudent
Set SelectStudent = iStudent
End Property 作者:
Nothing 时间: 2005-8-25 21:03