gmaxey
08-20-2019, 02:05 PM
I have the following two procedures in an Excel workbook. Can someone offer and explanation why the first runs as expected, but the second will not compile or run:
Sub CompareModeDemoI()
Dim oKey
'Compiles and runs without error.
With CreateObject("scripting.dictionary")
.CompareMode = 1
For Each oKey In Array("X", "Y", "Z", "x", "y", "z")
On Error Resume Next
.Item(oKey) = oKey
Next oKey
Debug.Print "Item Count: " & .Count
End With
End Sub
Sub CompareModeDemoII()
'This version will not compile or run.
Dim oDic As Object
Dim oKey
Set oDic = CreateObject("scripting.dictionary")
.CompareMode = 1 'Compile error invalid or unqualified reference.
For Each oKey In Array("X", "Y", "Z", "x", "y", "z")
On Error Resume Next
.Item(oKey) = oKey 'Here upper and lower case are not unique. Item content defiend same as key.
Next oKey
Debug.Print "Item Count: " & .Count
End With
End Sub
The second won't run with or without a reference scripting.runtime
Thanks
Sub CompareModeDemoI()
Dim oKey
'Compiles and runs without error.
With CreateObject("scripting.dictionary")
.CompareMode = 1
For Each oKey In Array("X", "Y", "Z", "x", "y", "z")
On Error Resume Next
.Item(oKey) = oKey
Next oKey
Debug.Print "Item Count: " & .Count
End With
End Sub
Sub CompareModeDemoII()
'This version will not compile or run.
Dim oDic As Object
Dim oKey
Set oDic = CreateObject("scripting.dictionary")
.CompareMode = 1 'Compile error invalid or unqualified reference.
For Each oKey In Array("X", "Y", "Z", "x", "y", "z")
On Error Resume Next
.Item(oKey) = oKey 'Here upper and lower case are not unique. Item content defiend same as key.
Next oKey
Debug.Print "Item Count: " & .Count
End With
End Sub
The second won't run with or without a reference scripting.runtime
Thanks