Error msg: "Item has already been added. Key in dictionary"

lornetw

Member
Licensed User
Longtime User
Hi. I have version 6.90 of BASIC4PPC and I am making a program for Windows Desktop only (it will never be used on a device) and I am having trouble with the following error message:

"An error occurred on sub main.openncfile

Line number : 239

FileOpen(CNCFile, CurrentNCFilenameAndPath, cRead,, cASCII)
Error description :
Item has already been added. Key in dictionary :
'_main_cncfile' key being added : '_main_cncfile'

Continue ? [Yes] [No]"

This occurs when I try to re-run my program a 2nd time (it works flawlessly the first time). It is a program I have made to pre-process a CNC G-Code file
to make header for a program called Predator (from Predator-software.com) that simulates the movements the CNC machine will make from the code
my machinist students create (I teach CNC programming in a trade school in Anjou (Montreal)).

I basically open their file, extract various information, add a header to the beginning of the file and resave it with a different name. However, when I try to rerun my program a second time, it gives the above error. The reason I want to rerun my program is because the students will be doing quite a few
programs (and simulating them to get feedback on the correctness of their programming) each night.

I have tried to clear out the reference to my previously opened file by doing the following before trying to re-open a different file (or even the same one?):
odEX.New1
Dim files(0)
- but this does not fix the problem. If there is no fix for this I will just get my students to close my program and completely restart it.

Would any one know how I could fix this? I did a search on the forum for BASIC4PPC but could't find anything applicable.

I also program in BASIC4Android and have made a program for my student machinists for various things that they do. I love the look I get from my students when I tell them I make apps for Android ! (I'm 62). Keep up the good work!!!! :sign0098:

Regards
Lorne Wilkins
 

Cableguy

Expert
Licensed User
Longtime User
heve you closed the file access?
In B4Ppc, a FileOpen comand locks the file on B4A so no other app can open it or change it...and it stays that way until you doa a FileClose...

In your case a FileClose(CNCFile) I think...I haven't used B4Ppc for a while...
 

lornetw

Member
Licensed User
Longtime User
Hi Cableguy. Thanks for your reply. In my code I indeed have a FileClose(CNCFile) but the error msg still happens.

I'll try some more stuff

Thanks

Lorne Wilkins
 

mjcoon

Well-Known Member
Licensed User
If there is no fix for this I will just get my students to close my program and completely restart it.
...
In my code I indeed have a FileClose(CNCFile) but the error msg still happens.

The first quote suggest that there is a difference between "re-running" and "restarting". Could you explain what this difference is?

Second quote makes me wonder if the FileClose() is (not) being executed. Could you add a pop-up message to verify this?

HTH (in due course!), Mike.
 

Cableguy

Expert
Licensed User
Longtime User
If you can post your project along with a file to read from, of even a partial project that reproduces the error, I would be happy to try to help you...
 

agraham

Expert
Licensed User
Longtime User
As suggested above it is almost certain that the file is not closed. Opening a file adds the connection name to an internal Hashtable of open files and closing a file removes the connection name. The error you are getting looks like the same connection name is trying to be added to the Hashtable in which all keys must be unique.
 

Subu

Member
Licensed User
I am making a database program for use with my students. I am facing the same problem, i.e. i get the same error message. This happened after I duplicated a button control & by mistake named it the same as previous button, when i closed the form i got a warning that two of my buttons were the same. I reopened the form & renamed the second button. But later wen i tried to run the file i got the aforementioned error message. As i didn't have time for research & experimentation. I closed the program file. I got around by opening my previous version of program & rewrote the last 30 mins of work. It probably has something to do with duplicating the name of a control & then it does not unduplicate that
 

mjcoon

Well-Known Member
Licensed User
I am making a database program for use with my students. I am facing the same problem, i.e. i get the same error message. This happened after I duplicated a button control & by mistake named it the same as previous button, when i closed the form i got a warning that two of my buttons were the same. I reopened the form & renamed the second button. But later wen i tried to run the file i got the aforementioned error message. As i didn't have time for research & experimentation. I closed the program file. I got around by opening my previous version of program & rewrote the last 30 mins of work. It probably has something to do with duplicating the name of a control & then it does not unduplicate that

Did the new button name, and the original, show up in the list of controls?

There's always the danger that the system tries to be helpful and when you change the name of something it goes and changes all references. That could result in no original names left and new duplicates!

Mike.
 
Top