Dictionary(of String, Integer)

Hello, I’m having trouble get the dictionary to work. I need it to be of integer value.
the variable declared is System.Collections.Generic.Dictionary(System.String, System.int32). the initialization is dict = new Dictionary(of string, integer) and I use a for each loop to grab the value of integer: dict(row(“BU_name”).ToString.Trim) =cint(row(“TreePosition”).tostring), but it threw an error conversion from string to integer not valid.

can someone please help?

Here you go with a sample on how to use a dictionary

We can try to use ADD TO DICTIONARY activity

Go to design tab → manage packages → install install the package Microsoft.Activities.Extensions in all package tab

And we can use that activity

Cheers @lynnsong986

Hello @lynnsong986

Here you go. This Article might help you.

And also the video for the same:-

Mark as a solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:


Create Value as Object instead of Integer. So that value will hold any type of value like Integer, String etc…

1 Like

give us some more details on the issue it could be the case that:

  • value is empty
  • value is within a format not parseable to an int

also trim the value cint(row(“TreePosition”).tostring .trim)

Thanks so much for helping me out. so I have the attached stored in an excel file that I need to feed the dict. I used the read range and for each row in datatable and the above mentioned variable and initialization. I just tried to change everything to object, but still got the same error. Capture

have a check on a values with text on col

in case of you want to create a dictionary from 2 cols from datatable you can do it also with a LINQ filtering out the non parseable values

Assign Activity
left: yourDictVar

(From d in dtData.AsEnumerable
Let v = row("TreePosition").tostring.trim
Where Int32.TryParse(v, nothing)
Let k = row("BU_name").ToString.Trim
Let i = Cint(v)
Select t=Tuple.Create(k,v)).toDictionary(Function (x) x.Item1,Function (x) x.Item2)

That should be int32 not integer.

Also, it’s pretty clear from the error message that you have the dictionary value as “Submetering, 31” instead of just “31”…

thanks, so I’m stuck here, how should I get this argument to work? I’m passing the value of integer to another workflow.

the item is from for each item in dict
you people are awesome! really appreciate it.


thanks I tried but the same validation error: Option strict on disallowing late binding? and I’ve changed the integer to object everywhere

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.