Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 09-01-2023, 06:16 AM
gmaxey gmaxey is offline Any way to test if item in an array is in an ArrayList? Windows 10 Any way to test if item in an array is in an ArrayList? 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
 

Tags
arraylist contains, dictionary, indexof



Similar Threads
Thread Thread Starter Forum Replies Last Post
Test, just a test Thomasordef Office 0 07-25-2019 10:43 AM
Student's t-test (T.TEST): how to get p value? seanspotatobusiness Excel 1 07-20-2018 05:46 AM
Any way to test if item in an array is in an ArrayList? How do I make a checkbox or dropdown item reference data in that specific section of the data array? dhare Excel Programming 2 02-24-2016 12:36 PM
Any way to test if item in an array is in an ArrayList? Copying data related to one item to worksheet with many instances of the same item nmp13 Excel 3 02-06-2016 02:13 AM
Any way to test if item in an array is in an ArrayList? Convert String Array to Integer Array from a User Input? tinfanide Excel Programming 4 12-26-2012 08:56 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft