Forum Discussion
JB_SE_ED
May 30, 2023Copper Contributor
Need help extracting data from an XML file and adding it to a WDP file
Hi, I'm working on a project that uses data from an XML file, which contains a unique file number(s) (Ex: E12345678-001-01) and a unit location(s) associated with that number (Ex: 1A) Using t...
LainRobertson
May 31, 2023Silver Contributor
Hi.
In a HashTable, the key must be unique - i.e. you cannot add the same key value twice.
I've reproduced the error you're seeing below, after which you can see how to use the ContainsKey() method of the HashTable class to check if a value already exists in a couple of additional examples.
You can read more about the methods and properties available on the HashTable class here:
Alternatively, you can leverage the "try {} catch {}" construct for a similar outcome.
try
{
$h.Add("key1", "value1");
}
else
{
# Handle the error condition in here however, you see fit, such as
# log it to the screen, one of the output streams, a file, or maybe just do nothing at all.
}
The bottom line is you will get errors if you try and add the same key more than once. How you handle that is up to you, but not handling that key uniqueness restriction is why you're seeing what you're seeing.
Cheers,
Lain