一楼正解,我在一篇帖子里回过这个问题,在这儿再帖一遍方案: 可以先定义一个Private数组,然后用属性索引的方法访问'-------------------------------------------------------------------- Private Const mconArraySize As Integer=10 Private mintArray(1 to mconArraySize) As DoublePublic Property Get Array(ByVal intIndex As Integer) As Double If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then Err.Raise 381 '无效属性参数值 End if Array=mintArray(intIndex) End PropertyPublic Property Let Array(Byval intIndex As Integer,Byval dblValue As Double) If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then Err.Raise 381 '无效属性参数值 End if mintArray(intIndex) = dblValue End Property使用这个属性跟使用一个数组一样: i = objMyObj.Array(2) objMyObj.Array(1) = 5.3
Private Const mconArraySize As Integer=10 Private mintArray(1 to mconArraySize) As DoublePublic Property Get Array(ByVal intIndex As Integer) As Double If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then Err.Raise 381 '无效属性参数值 End if Array=mintArray(intIndex) End PropertyPublic Property Let Array(Byval intIndex As Integer,Byval dblValue As Double) If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then Err.Raise 381 '无效属性参数值 End if mintArray(intIndex) = dblValue End Property使用这个属性跟使用一个数组一样: i = objMyObj.Array(2) objMyObj.Array(1) = 5.3 ------------------------------ 这样比较好
我建议采用后一种方法
可以先定义一个Private数组,然后用属性索引的方法访问'--------------------------------------------------------------------
Private Const mconArraySize As Integer=10
Private mintArray(1 to mconArraySize) As DoublePublic Property Get Array(ByVal intIndex As Integer) As Double
If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then
Err.Raise 381 '无效属性参数值
End if
Array=mintArray(intIndex)
End PropertyPublic Property Let Array(Byval intIndex As Integer,Byval dblValue As Double)
If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then
Err.Raise 381 '无效属性参数值
End if
mintArray(intIndex) = dblValue
End Property使用这个属性跟使用一个数组一样:
i = objMyObj.Array(2)
objMyObj.Array(1) = 5.3
窗体---是房间
模块中用public声明的大家都可直接访问
窗体中用public声明的可以用Form2.xxx访问
用Private声明的只有各自用了
Private mintArray(1 to mconArraySize) As DoublePublic Property Get Array(ByVal intIndex As Integer) As Double
If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then
Err.Raise 381 '无效属性参数值
End if
Array=mintArray(intIndex)
End PropertyPublic Property Let Array(Byval intIndex As Integer,Byval dblValue As Double)
If ( intIndex < 1 ) Or ( intIndex > mconArraySize ) Then
Err.Raise 381 '无效属性参数值
End if
mintArray(intIndex) = dblValue
End Property使用这个属性跟使用一个数组一样:
i = objMyObj.Array(2)
objMyObj.Array(1) = 5.3
------------------------------
这样比较好