Ale*_*ing 5 excel vba class subclass excel-vba
我正在使用Excel VBA在那里我有很多的数据集的一个项目,每一个填充了一系列的"病人",这有很多的参数(如治疗,预后等).为了解决这个问题,我打算创建一个名为"患者"的类,其中包含治疗和结果等属性.然后创建一个名为"dataset"的类,其公共属性为"patient".我已经创建了类,我可以实例化一个数据集对象.但是,如何在数据集对象中实例化患者对象,或理想情况下是一组患者对象?
数据集类模块:
Private pNumber As Integer
Public Patient As Patient
Public Property Get Number() As Integer
Number = pNumber
End Property
Public Property Let Number(p As Integer)
pNumber = p
End Property
Run Code Online (Sandbox Code Playgroud)
患者类模块:
Private pID As Integer
Private pTreatment As Boolean
Private pResponse As Single
Public Property Get ID() As Integer
ID = pID
End Property
Public Property Let ID(p As Integer)
pID = p
End Property
Public Property Get Treatment() As Boolean
Treatment = pTreatment
End Property
Public Property Let Treatment(p As Boolean)
pTreatment = p
End Property
Public Property Get Response() As Single
Response = pResponse
End Property
Public Property Let Response(p As Single)
pResponse = p
End Property
Run Code Online (Sandbox Code Playgroud)
主要模块
Sub main()
Dim data1 As Dataset
Set data1 = New Dataset
'code to instantiate array of patient within data1 here
End Sub
Run Code Online (Sandbox Code Playgroud)
数据集将被更好地指定为这样的。
我会按照它的预期名称来称呼这个类,所以Patients:
private colPatients as new collection
public function add(aPatient as patient)
colPatients.add aPatient, aPatient.Id
end function
public property get count() as long
count = colPatients.count
end property
public property get items() as collection
set items = colPatients
end property
public property get item(vItem as variant) as patient
set item = colPatients(vItem)
end property
public sub remove(vItem as variant)
colPatients.remove vItem
end sub
Run Code Online (Sandbox Code Playgroud)
所以要使用:
dim patientCollection as patients
Sub main()
Set patientCollection = New patients
'code to instantiate array of patient within data1 here
IDs = Array(1,2,3)
treats = array("x","y","z")
dim x as integer
dim p as patient
for x = lbound(IDs) to Ubound(IDs)
set p= new patient
p.id = IDs(x)
p.treatment = treats(x)
patientCollection.add p
set p = nothing
next x
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
439 次 |
| 最近记录: |