vb6的dictionary类

发布时间 2023-08-10 21:37:11作者: harrychinese

vb6的dictionary类

vb6 原生容器, 除了array还有collection, 没有原生的dictionary和set类, 在microsoft script runtime库(scrrun.dll) 中有一个dictionary类, 功能还算强大, 可以较好处理key-value这样的字典, 我甚至觉得用它也完全可以代替原生的collection类.
microsoft script runtime库(scrrun.dll)中还包含了FileSystemObject 和 File 和 TextStream 常用的类.

    sub DictionaryTest()
        dim  dict as new dictionary 
        dim i as integer 
        dim txt as string 
        
        call dict.add("a","a1")  ' 增加一个key-value 
        call dict.add("d","d1")  
        
        dict.item("d") ="d2"  ' 修改指定key的value
        dict("d") ="d3"       ' 另一种方法去修改指定key的value 
        
        for i=0 to dict.count -1   '遍历dictionary, 下标要从0 开始 
            txt=dict.keys()(i) ' 使用 keys() 返回key的数组, 然后获取指定下标的key 
            txt=dict.items()(i) ' 使用 items() 返回value的数组, 然后获取指定下标key对应的value
            txt=dict.items(i) ' 获取指定下标key对应value的另一种方法, 使用 dic.items()(i) 可以简写成 dict.items(i)
        next i 
    end sub 

vb6 模拟实现的C#基本类库

https://github.com/kellyethridge/VBCorLib/tags