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.
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.
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
(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)