View Single Post
 
Old 09-01-2023, 06:16 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Andrew, sweet!

That solution should be booked as a function! Here is my stab:

Code:
Sub Test()
Dim oDic As Object
  Set oDic = CreateObject("Scripting.Dictionary")
  oDic.Add "1", "Apples"
  oDic.Add "2", "Blue Berries"
  oDic.Add "3", "Cherries"
  'Where the "Exists" method tells us if a key is present in a dictionary ...
  MsgBox oDic.Exists("1")
  '... the following function tells us if a value exists
  MsgBox fcnDicValueExists(oDic, "Cherries") 
lbl_Exit:
  Set oDic = Nothing
  Exit Sub
End Sub
Function fcnDicValueExists(oDicPassed, varValue) As Boolean
'Created from suggestions offered by Andrew Lockton in the Word VBA Forum.
Dim oArrList As Object, varMembers, varString
  'Convert dictionary list members to an ArrayList
  Set oArrList = CreateObject("System.Collections.Arraylist")
  oArrList.Add oDicPassed.Items
  'Convert ArrayList to array
  varMembers = oArrList.ToArray
  'Join array element members to a delimited string
  varString = Join(varMembers(0), "|") & "|"
  'Test if value found in string
  fcnDicValueExists = InStr(varString, varValue & "|") > 0
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote