| 发表于:2007-09-20 20:38:3511楼 得分:5 |
可以自己写一个类来替换collection 下面这段代码只是随性写的,可能还存在部分考虑不完善的地方,看看有没有人进一步补充完善 创建一个类模块,命名为mycollection 代码如下: option explicit private colkey as new collection private colval as new collection public property get count() as long count = colkey.count end property public property get realcol() as collection set realcol = colval end property public sub add(item, optional key, optional before, optional after) colkey.add key, key, before, after colval.add item, key, before, after end sub public sub remove(index) colkey.remove index colval.remove index end sub public function getkey(index) as string getkey = colkey.item(index) end function 下面我们用一些代码来测试一下collection特性是否保留,并且我们能不能通过索引号获得key 建个窗体,放个按钮 private sub command1_click() dim a as new mycollection '创建实例 '加入对象 a.add "test1 ", "key1 " a.add "test2 ", "key2 " a.add "test3 ", "key3 " a.add "test4 ", "key4 " a.add "test5 ", "key5 " debug.print "用索引号方式获取对象 " debug.print a.realcol(2) debug.print "用key获取对象 " debug.print a.realcol( "key3 ") debug.print "remove对象 " a.remove "key2 " debug.print "for each访问 " dim b for each b in a.realcol debug.print b next debug.print "罗列所有key " dim i as integer for i = 1 to a.count debug.print a.getkey(i) next debug.print "异常测试 " a.add "asdad ", "key5 " '重复key a.remove "key6 " '删除不存在的对象 a.getkey 8 '获取不存在的key end sub | | |
|