|
楼主 |
发表于 2013-11-3 19:09
|
显示全部楼层
本帖最后由 liucqa 于 2013-11-3 19:20 编辑
如果需要将数据放入数组,以方便在工作表中输出,也可以采用类模块解决。
类模块clsItem 代码
- Option Explicit
- Public name As String
- Public id As String
- Public idx As Long
- Private data()
- Public Sub RedimData(ByVal l As Long, ByVal r As Long)
- ReDim data(l To r)
- End Sub
- Public Sub InputData(ByVal str As String, ByVal i As Long)
- data(i) = str
- End Sub
- Public Property Get Outputdata() As Variant
- Outputdata = data
- End Property
- Private Sub Class_Initialize()
- End Sub
- Private Sub Class_Terminate()
- Erase data
- End Sub
复制代码
标准模块代码
- Sub testCls()
- Dim dic As Object, i&, j&
- Dim item As clsItem
- Set dic = CreateObject("Scripting.Dictionary") '后期绑定引用字典对象
- For i = 1 To 3
- Set item = New clsItem
- item.name = "name" & i
- item.id = "id" & i
- item.idx = i
- '定义用于输出的数组大小
- Call item.RedimData(0, 3)
- For j = 0 To 3
- Call item.InputData("key" & i & "data" & j, j) '给数组赋值
- Next
- dic.Add "key" & i, item
- Set item = Nothing
- Next
- [A1:C1] = dic("key2").Outputdata '输出
- Set dic = Nothing
- End Sub
复制代码
附件下载
字典一对多,类模块.rar
(19.4 KB, 下载次数: 1843)
|
|