View Single Post
 
Old 02-02-2025, 09:37 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Batman,


Yes, you were correct. You seem to have a very good handle on dictionary. Perhaps you can explain why this code errors:


Code:
Sub Test()
Dim oDic As Object, oKey
Dim varVals
Dim lngIndex As Long
   varVals = Split("APPLES,Apples,Pears,Pears,PEARS,pears,Blueberries,APPLES", ",")
   Set oDic = CreateObject("Scripting.Dictionary")
   oDic.CompareMode = 1
   For lngIndex = 0 To UBound(varVals)
     If oDic.Exists(varVals(lngIndex)) Then
       oDic.Item(varVals(lngIndex)) = oDic.Item(varVals(lngIndex)) + 1
     Else
       oDic.Add varVals(lngIndex), 1
     End If
   Next
   For Each oKey In oDic.Keys
     MsgBox oKey & " count = " & oDic.Item(oKey)
   Next oKey
   'Why can't set oKey to a spefic key index e.g.:
   oKey = oDic.Keys(1).Value  'Errors here
   MsgBox oKey & " count = " & oDic.Item(oKey)
lbl_Exit:
  Exit Sub
End Sub
Looking at the Debugger Watches windows, oDic.Keys(1) definitely has a value.
Attached Images
File Type: jpg Error.jpg (105.6 KB, 11 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote