I have an application in which three programs share some files. Each program checks one particular file to see if it is set as a one or a zero. A one says that other files are in use, while a zero says that they are free. The program then sets the file back to a zero after it is done. I received a run-time error stating: Input past end of file. My hunch here is that one program attempted to read an empty file. This would only seem likely to happen if the program had attempted to read from a file that had been read by another file, but had not yet been updated with a zero. Here is the code that I use when checking the file:
Open MWIFile_In_Use For Input As #MWIFile_In_UseFB 'Sets
flag bit to unbusy
Lock #MWIFile_In_UseFB
Read #MWIFile_In_UseFB, MWIFuseStatus
Unlock #MWIFile_In_UseFB
Close
This is the code that I use when setting the file back to zero:
Open MWIFile_In_Use For Output As #MWIFile_In_UseFB 'Sets
flag bit to unbusy
Lock #MWIFile_In_UseFB
Write #MWIFile_In_UseFB, 0
Unlock #MWIFile_In_UseFB
Close
I'm curious as to how likely it is that one program happened to access the file during the brief instant that another program did not have control of it. I have been running these programs with a fairly steady stream of data 24/7 for about 35 days and just had the first error.
I do realize that using a database would have been a better approach for this issue, but I would prefer to stick with my current programs if this is not an error that will be common. An incident once every month or two is probably acceptable.
Any thoughts?
Thank you,
Jesse
Open MWIFile_In_Use For Input As #MWIFile_In_UseFB 'Sets
flag bit to unbusy
Lock #MWIFile_In_UseFB
Read #MWIFile_In_UseFB, MWIFuseStatus
Unlock #MWIFile_In_UseFB
Close
This is the code that I use when setting the file back to zero:
Open MWIFile_In_Use For Output As #MWIFile_In_UseFB 'Sets
flag bit to unbusy
Lock #MWIFile_In_UseFB
Write #MWIFile_In_UseFB, 0
Unlock #MWIFile_In_UseFB
Close
I'm curious as to how likely it is that one program happened to access the file during the brief instant that another program did not have control of it. I have been running these programs with a fairly steady stream of data 24/7 for about 35 days and just had the first error.
I do realize that using a database would have been a better approach for this issue, but I would prefer to stick with my current programs if this is not an error that will be common. An incident once every month or two is probably acceptable.
Any thoughts?
Thank you,
Jesse