compare 2 lists

My dept runs a script to uninstall unwanted software. Here’s what I want to do. I can generate a list of installed software using the wmic command. How can I compare those lists to make sure the software I want to remove has been removed. Essential compare the lists and if a software I don’t want is in both enable a certain label.


list 1 has mcafee
list 2 has mcafee

list 1 has mcafee
list 2 does not


Turn list1 into a Dictionary and use HasKey to see if items on list2 are in the Dictionary.

Sort the lists and do a sequential match ( like we had to do in the old days with multiple tape drives :wink: ).

A simple brute force way is myArray.IndexOf. It returns the first index a value appears in the array, or -1 if not found. So if the index is >= 0 the value is in the array, otherwise not.

for i As integer = 0 to list1.Ubound if list2.IndexOf( list1(i) ) >= 0 then //list2 has list1(i) else //list2 doesn't have list1(i) end next

For a smallish list, Will’s suggestion might even be faster than a Dictionary.

Awesome, next question. I’ve gotten the data into a list but it’s the 3rd word of each line that I need. Any thoughts on how to get that 3rd word of each line?

Thanks for the assistance, I’m very new to this.


Use NthField(theLine, " ", 3)