Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a file that doesn't exist yet???

Status
Not open for further replies.

DJKAOS

Technical User
Jun 30, 2000
101
US
I'm using Access97 but can't find the answer in those forums, this is mainly a Visual Basic question.

How do I create a blank file?
Right now I am using.
Open "test.txt" as input for #1
'read the data in.
close #1

the problem is it crashes if text.txt doesn't exist....how
do I create a file on the fly? I would have thought the Open
command should do it automatically.. C++ does.

so to get around it I Have had to manually make the files with Notepad...however this wont work forever because it needs to create files on the fly.

QUESTION #2...how can I check if a file is blank?

Thanks
 
if dir("test.txt") = "" then
' create empty file
Open "test.txt" for ouput as #1
close #1
end if

if filelen("test.txt") = 0 then
msgbox "file is empty"
else
Open "test.txt" for input as #1
'read the data in.
close #1
end if
 
Thanks I Think I figured out my problem....
my FileName string had stuff like "1 1/2 X 0.txt"
which is an illegal file name because of the /

At least I'm hoping thats what the problem was I'll have to try fixing it on monday.
 
That is a common problem!
The generic solution, as already posted here, is to
ALWAYS open/create the file, ten immediately close it -
that way, you're assured that it ALWAYS will exist. Then
re-open the file for reading.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top