Whilst creating this program in visual studio 2010 i have encountered a problem.
I read in contents of a textfile and search through each line to make sure when adding a new product, that their are no existing IDs the same. contents of file look like this:
0001|Unsmoked Middle Bacon
0002|Smoked Middle bacon
0003|Unsmoked Bits
So if a user tries to add a value ‘0001’ it springs an error. Only my code is springing an error…
appPath = Application.StartupPath
productDB = New Dictionary(Of Integer, String)
For Each line In IO.File.ReadAllLines(appPath & "/productlist.txt")
Dim data = line.Split("|")
productDB.Add(CInt(data(0)), data(1))
Next
If productDB.ContainsKey(newID) Then
MsgBox("Prompt of same ID")
Else
MsgBox("Accepted fine")
End If
on the line – productDB.Add(CInt(data(0)), data(1)) – I seem to be springing the error
ArgumentException was unhandled.
An item with the same key has already been added.
Alot of people have been mentioning their resources.resx file messing things up, but i have tried all sorts and nothing seems to be helping 🙁
cheers,
robbie.
My own silly mistake.
There was already a duplicate entry within the textfile. (I had about 40 lines)
So it wasn’t anything to do with the 4 digits I was wanting to enter, the error was happening upon reading in each line.