Hello I have a dictionary (of string, object) where key is a string and value is integer. I got the dictionary working (thanks to people who helped me here, and I tested it)
I’m using a for each to pass the value of each key to another workflow, but I got validation error saying option strict disallowing late binding. I get the same error if I use cint(item.value). Can someone please help?
I tried both but still got the same validation error. When I typed item. I don’t see value as one of the properties but the dictionary works as I tested it using (dictTest.ElementAt(0).Key).tostring + (dictTest.ElementAt(0).Value).string in a message box…
thanks! but now I’m getting a different error after changing the typeArgument…tried to change the dict to of string, int32, but got the same validation error…
For Each item in Dict - what is the For Each TypeArgument set to?
Assuming it’s set to string as it should be, then item represents the key but the right side needs to be Dict.Keys. So to get the value you do Dict(item).ToString and if you need it as an integer you do CInt(Dict(item).ToString)
Thanks Paul! It’s my first time using dictionary in UIpath so now I learnt that I need to set the type argument properly. So much appreciated for your time!
Dictionaries are fantastic. I use them for many things. As you see here, there are multiple ways to get at their values. And the SpecificContent dictionary is the key to Queue Items (Transactions).
I visualize a dictionary like this, let’s call it myDict:
{
Name : Paul
City : Miami
Country: USA
}
Assign myDict(“Name”) = “Tom” – to change the Name
myDict(“City”).ToString – to get the value of City
myDict.Keys – gives you an array {“Name”,“City”,“Country”} which you For Each through
myDict.Values – gives you an array {“Paul”,“Miami”,“USA”} which you can For Each through
It’s important to understand the “of xxxxx, zzzzz” part of a dictionary. Usually you’ll want Dictionary(of string, object) - this means the key (ie Name, City, etc) is a string. But the value is an object so it can be anything (string, int32, boolean, etc)
One time I even did a Dictionary(of string, system.data.datatable) and used a dictionary to store a bunch of datatables I needed to interact with.