求教 Collection 的使用方法,存放的对象还原问题

比特灵 2013-06-05 09:11:00
尝试使用Collection存放数组,可以存进去,但是怎么拿出来,还原为数组?

以下的代码在取出的部分报错:


Dim list as Collection

'存放
Dim arr(0 to 2) as String
list.add arr
...

'取出
Dim aa(0 to 2) as String
for i=1 to list.Count
set aa = list.item(i)‘报错
debug.print aa(0)
next i


...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
比特灵 2013-06-05
  • 打赏
  • 举报
回复
原来可以不用转换,可以直接用: list.Item(i)(0) list.Item(i)(1) 习惯用JAVA的思维了。 多谢各位回复
worldy 2013-06-05
  • 打赏
  • 举报
回复
Private Sub Command3_Click() Dim A(3) As Long Dim T As New Collection Dim B() As Long Dim i As Long T.Add A B = T(1) For i = 0 To 3 Debug.Print B(i) Next End Sub
worldy 2013-06-05
  • 打赏
  • 举报
回复
引用 楼主 bigc2001 的回复:
尝试使用Collection存放数组,可以存进去,但是怎么拿出来,还原为数组? 以下的代码在取出的部分报错:

Dim list as Collection

'存放
Dim arr(0 to 2) as String
list.add arr
...

'取出
Dim aa(0 to 2) as String
for i=1 to list.Count
   set aa = list.item(i)‘报错
   debug.print aa(0)
next i
Dim list as Collection set list=new collection ....
比特灵 2013-06-05
  • 打赏
  • 举报
回复
[quote=引用 2 楼 photel123456 的回复:] 怎么转化为String? 我是想把一个个的数组存到list中,不是数组中的一个个字符串。 既: 存的是数组对象,怎么做对象还原? 谢谢两位。
lliai 2013-06-05
  • 打赏
  • 举报
回复
Dim thisCustomer As Object While list.MoveNext() thisCustomer = list.Current() End While 然后再转为STRING
Tiger_Zhao 2013-06-05
  • 打赏
  • 举报
回复
'存放
Dim arr(0 To 2) As String
For i = 0 To 2
list.Add arr(i)
Next


'取出
Dim aa(0 To 2) As String
For i = 1 To list.Count
aa(i - 1) = list.Item(i)
Debug.Print aa(i - 1)
Next i

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧