怎么在VB中给数组元素的每个下标一个变量名,就像定义参数一样?
问题描述:
怎么在VB中给数组元素的每个下标一个变量名,就像定义参数一样?不同的下标表示不同的变量名在VB的实现是?
答
那么就封装成函数/属性好了。
'类 Table
Option Explicit
Option Base 1
Private m_Cells() As Long
Public Sub DefineSize(ByVal RowCount As Long, ByVal ColCount As Long)
ReDim m_Cells(RowCount, ColCount)
End Sub
Public Property Get Cells(ByVal Row As Long, ByVal Col As Long) As Long
Cells = m_Cells(Row, Col)
End Property
Public Property Let Cells(ByVal Row As Long, ByVal Col As Long, ByVal RHS As Long)
m_Cells(Row, Col) = RHS
End Property
调用
Option Explicit
Sub Main()
Dim t As Table
Set t = New Table
Call t.DefineSize(2, 3)
t.Cells(1, 2) = 3 '<-这里自动提示参数'
End Sub