Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-31-2023, 11:44 PM
Guessed's Avatar
Guessed Guessed 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 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I would do this by converting the ArrayList to an Array and then use Join with a delimiter to get all the contents into one string. Then use InStr to find out if the element exists. For example
Code:
Sub dicItemExists_Test()
  Dim i As Long, dicTest As Object
  Dim arList As Object, arr As Variant, str As Variant, sFind As String
  
  Set dicTest = CreateObject("Scripting.Dictionary")
  Set arList = CreateObject("System.Collections.Arraylist")
  
  dicTest.Add "Key2", "Item 2"
  dicTest.Add "Key3", "Item 3"
  dicTest.Add "Key1", "Item 1"
  
  arList.Add dicTest.Items
  arr = arList.ToArray
  str = "|" & Join(arr(0), "|") & "|"
  sFind = "|" & "Item 4" & "|"
  Debug.Print InStr(str, sFind) > 0

  sFind = "|" & "Item 3" & "|"
  Debug.Print InStr(str, sFind) > 0
End Sub
I'm thinking if you are using this for a listbox then you already have an array to work with so the code can be a lot more direct than fiddling with dictionary and arraylist
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
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