Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-29-2023, 05:19 PM
skarden skarden 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 2010 64bit
Novice
Any way to test if item in an array is in an ArrayList?
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 26
skarden is on a distinguished road
Question Any way to test if item in an array is in an ArrayList?

I'm trying to see if I can come up with a way to tell if an item exists in a dictionary without having to iterate through it with a For Each type of loop. My idea was to put the items into an ArrayList and then use ArrayList.Contains or ArrayList.IndexOf to see if it was in there. I can prove that I've put the items into the ArrayList as an array, but I can't figure out the syntax to then test if it is in there using either ArrayList.Contains or ArrayList.IndexOf of.

Below is an example of using .Contains. You'll see the Debug.Print proves it is in there in an array, but I can't figure out how to get .Contains to find it or .IndexOf to find it.
So am I correct (sadly) that there is now such way?

Sub dicItemExists_Test()

On Error GoTo lblError

Dim i As Long

Dim arList As Object
Dim dicTest As Object

Set arList = CreateObject("System.Collections.Arraylist")

Set dicTest = CreateObject("Scripting.Dictionary")



dicTest.Add "Key2", "Item 2"
dicTest.Add "Key3", "Item 3"
dicTest.Add "Key1", "Item 1"

arList.Add dicTest.Items

Debug.Print "arList.Item(0)(0) = " & arList.Item(0)(0) 'This proves "Item 2" is in there

If arList.Contains("Item 2") Then
MsgBox "Item 1 was found", vbInformation + vbOKOnly, "ArrayList test"
Else
MsgBox "Item 1 was not found", vbInformation + vbOKOnly, "ArrayList test"
End If

lblExit:
Set dicTest = Nothing
Set arList = Nothing
Exit Sub

lblError:
Debug.Print "Got error: " & Err.Number & ", " & Err.Description
GoTo lblExit

End Sub
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 08:22 PM.


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