|
- Sub kong()
- Set dic = CreateObject("scripting.dictionary")
- dic("A") = 1
- dic("B") = 1
- dic("D") = 1
- dic("C") = 1
-
- aa = String(9, "@") ''连接符
- bb = Len(aa) ''连接符长度
- cc = aa & Join(dic.keys(), aa) & aa ''字典 keys 转字符串
- dd = InStr(cc, aa & "B" & aa) ''字典 keys 字符串 中找 B 字符串索引
- ee = dd \ bb ''字典中 B 字符串索引
- Debug.Print ee, dic.keys()(ee) ''字典中 B 字符串索引 ,对应索引 key
- If dic.exists("C") Then ''字典 keys 中找 C 字符串
- ff = Dictionaryindex(dic, "C")
- Debug.Print ff, dic.keys()(ff) ''字典中 B 字符串索引 ,对应索引 key
-
- gg = WorksheetFunction.Match("C", dic.keys()) + 1
- Debug.Print gg, dic.keys()(gg) ''字典中 B 字符串索引 ,对应索引 key
- End If
- If dic.exists("A") Then ''字典 keys 中找 C 字符串
- ff = Dictionaryindex(dic, "A")
- Debug.Print ff, dic.keys()(ff) ''字典中 B 字符串索引 ,对应索引 key
-
- gg = WorksheetFunction.Match("A", dic.keys()) + 1
- Debug.Print gg, dic.keys()(gg) ''字典中 B 字符串索引 ,对应索引 key
- End If
- End Sub
- '' aa 为字典 , bb 为查找的 key
- Function Dictionaryindex(ByVal aa As Object, bb)
- If TypeName(aa) <> "Dictionary" Then Exit Function
- If Not aa.exists(bb) Then Exit Function
- a = String(9, "@") ''连接符
- B = Len(a) ''连接符长度
- C = a & Join(aa.keys(), a) & a ''字典 keys 转字符串
- D = InStr(C, a & bb & a) ''字典 keys 字符串 中找 bb
- f = D \ B ''字典中 bb 字符串索引
- Dictionaryindex = f
- End Function
复制代码 |
|