0

出于某种原因,我无法将CompareMode字典offONameDic中的TextCompare. 我不断得到一个"Invalid Procedure or Call Error". 我想确保用户提供的密钥的大写不会影响字典将密钥识别为有效的能力,即如果密钥是“hello”,“Hello”也将被识别为密钥。

请注意,我使用 VBA Excel 中已安装库列表中的 Microsoft 脚本运行时参考

我的代码:

Sub Main()
'...code...
Dim offONameDic As Scripting.Dictionary
'...code...
Set offONameDic = New Scripting.Dictionary
With offONameDic
    .Add "Blood", "Blood"
    .Add "Liver", "Liver"
    .Add "Kidneys", "Kidneys"
    .Add "Kidney", "Kidneys"
    .Add "Spleen", "Spleen"
    .Add "Heart", "Heart"
    .Add "Lungs", "Lungs"
    .Add "Lung", "Lungs"
    .Add "Stomach", "Stomach"
    .Add "Muscle", "Muscle"
    .Add "Bone", "Bone"
    .Add "Carcass", "Carcass"
    .Add "Tumor", "Tumor"
    .Add "Axial Lymph Node", "Axial Lymph Node"
    .Add "ALN", "Axial Lymph Node"
    .Add "Igunial Lymph Node", "Igunial Lymph Node"
    .Add "IgLN", "Igunial Lymph Node"
    .Add "Intestines", "Intestines"
    .Add "Intestine", "Intestines"
    .Add "Cecum", "Cecum"
    .Add "Tail", "Tail"
    .CompareMode = TextCompare '****This Line Causes the "Invalid Procedure or Call" Error"****
End With
'...code...
End Sub
4

1 回答 1

3

您需要在将任何数据添加到字典之前CompareMode设置属性,因此将导致错误的行移到该行之后的第一个,例如:With offONameDic

With offONameDic
    .CompareMode = TextCompare ' No longer gives an error!
    .Add "Blood", "Blood"
    ...

根据文档

如果您尝试更改已包含数据的 Dictionary 对象的比较模式,则会发生错误。

于 2014-08-13T23:10:26.783 回答