What kind of file is it?
the technique a lot of programs (including MS Office Apps, SolidWorks, Etc..) use is to create a temporary file with a ~prefix such as
if the original was:
file.txt
the temp file would be:
~file.txt
then say:
if Dir("~file.txt") = "" then
...Open the file, Blah Blah, Close, etc...
End If
Otherwise, you could use the On Error commands to trap the error and skip to the part after the File Operation..
Code:
Function FileOpen(File as string) As Boolean
FileOpen = True
On Error Goto OpenFailed
If Dir(File)<>"" Then
Open File for input as #1
Close
FileOpen = False
End If
OpenFailed:
End Function
This Function will return:
True if the File is Not Open and Does Exist
False if the File is Open or Does Not Exist
I think there is a function like freefile, or something, you may want to use in place of #1, but that is the general structure to use...
the best thing to do is to Open a file, load the file to memory, then close the file asap to avoid these types of problems, you can the view/modify the file from the memory buffer as you like, then save it back to the file...
This code Opens a file, loads it, changes the characters to upper case, then saves it back to the file.
Code:
Dim TextBuffer as string
Open "File.txt" For Input as #1
TextBuffer = Input(LOF(1),#1)
Close
TextBuffer = UCase(TextBuffer)
Open "File.txt" For Output As #1
Print #1, TextBuffer
Close
Good Luck,
Josh
Have Fun, Be Young... Code BASIC
-Josh
PROGRAMMER:
Red-eyed, mumbling mammal capable of conversing with inanimate objects.