Will_Tyler
(Will Tyler)
February 13, 2018, 4:42pm
1
I can’t seem to get my keys loaded into my dictionary. I have the an assign showing
Out_Config = new Dictionary(of String, object)
This is reading my config file. As it finds the lines I have
out_Config(row(“Name”).ToString.Trim) = row(“Value”)
But when I check for the key value using a message box with
out_Config.keys.Contains(“[Name of the key]”).ToString
it comes back as false all the time.
arivu96
(Arivazhagan A)
February 13, 2018, 4:51pm
2
Hi @Will_Tyler
use below code check.
out_Config.keys.Contains(“Name of the key”)
Regards,
Arivu
Will_Tyler
(Will Tyler)
February 13, 2018, 5:07pm
3
Hey @arivu96 ,
I put in brackets the name to try and differentiate that it wasn’t the value I was looking for. If I don’t use the .ToString I get the following error. Thoughts?
arivu96
(Arivazhagan A)
February 13, 2018, 5:16pm
4
Hi @Will_Tyler ,
use below code if you want to be in message box activity
out_Config.Keys.Contains("System1URL").ToString()
If you are using If Condition use the below code
out_Config.Keys.Contains("System1URL")
Regards,
Arivu
I just happened to be working with my dictionary and I see that Keys.Contains doesn’t work, so what I tried was .ToArray and then you can check the indexof
Array.IndexOf(out_Config.Key.ToArray,"System1URL")
EDIT: add .ToString for messagebox
so you can try that method.
Regards.
Will_Tyler
(Will Tyler)
February 13, 2018, 5:27pm
6
Hi @ClaytonM
Thanks for the reply. I threw what you gave me into the message box and get this error
This shouldn’t be that difficult. I’ve seen videos of the task being run but I just can’t get it.
Sorry, it’s Keys
Array.IndexOf(out_Config.Keys.ToArray,"System1URL") > -1
arivu96
(Arivazhagan A)
February 13, 2018, 5:30pm
8
Hi @ClaytonM ,
given syntax is wrong, dict.Keys.Contains(“keyname”) it will return the true/false based on the value exists.
@ClaytonM correct me if i am wrong
out_Config.Keys.Contains("System1URL")
it will work
make sure object is created for dictionary
Regards,
Arivu
arivu96
(Arivazhagan A)
February 13, 2018, 5:31pm
9
HI @Will_Tyler ,
use this code
out_Config.Keys.Contains("System1URL").ToString()
Regards,
Arivu
Right but for some reason it’s not checking in the keys for a key that contains that text. When I did it, it always was False.
So in my method I convert the Keys to a list/array, which works. Maybe there’s a slight syntax problem as to why the .Contains is not working.
Additionally, I could list all the Keys by doing
String.Join(vblf,out_Config.Keys.ToArray)
1 Like