当字典位于数组中时,我想通过使用键“ first”来访问字典值“ Watermelon”。我相信这是将字典插入数组的正确方法。我已经尝试了所有可以想到的语法组合,并且无法在字典位于数组中的任何地方找到答案。
Function dictTest() As Object
Dim m_info As Dictionary
Set m_info = New Dictionary
m_info.Add "first", "watermelon"
Set dictTest = m_info
End Function
Sub checker()
Dim x(1 to 1) As Object
Set x(1) = dictTest
End Sub
最佳答案
这应该为您工作:
Function dictTest() As Object
Dim m_info As Object
Set m_info = CreateObject("Scripting.Dictionary")
m_info.Add "first", "watermelon"
Set dictTest = m_info
End Function
Sub checker()
Dim x(1 To 1) As Object
Set x(1) = dictTest
MsgBox x(1)("first")
End Sub