#1
|
|||
|
|||
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 |
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 |
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 |
Copying data related to one item to worksheet with many instances of the same item | nmp13 | Excel | 3 | 02-06-2016 02:13 AM |
Convert String Array to Integer Array from a User Input? | tinfanide | Excel Programming | 4 | 12-26-2012 08:56 PM |