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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a .Txt file 2

Status
Not open for further replies.

jsmokey

Technical User
Aug 19, 2005
10
US
Hi,
I was wondering what the command to create an empty text file was. Suppose i wanted to create a .txt file in the C drive called "practice.txt". Anyone know how to create an empty txt file from scratch? thanks
 
There are plenty of ways. Probably the most simple is just:


dim i as integer

i = freefile()

Open "C:\string\path\practice.txt" For Output as i


This code will create the file if it does not exist.
 
A starting point:
Open "C:\practice.txt" For Output As #1
Close #1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hey guys,
I have some similar code to that, but for some reason when i run the program on some of the other computers over here, it gives me an error because the file does not exist. it says something about "data path invalid" and ive looked over the code numerous times and it seems like the error is happening because it thinks im trying to open a file that does not exist. Basically, im saying is there any way to create a file without the implied logic that if it doesnt exist, it will be created automatically? The version that PHV wrote is what i do in my program and im getting an error on that line because the file doesnt exist. Thanks
 
Have you the right permissions to create a file in tha directory ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Phv,
yes i have the file permissions in the directory. We have a network here that everyone has access to, and assuming that the person's computer that it doesnt work on is my boss, i would say that they definately have permissions on that network drive. Strangely, the only persons computer my program doesnt work on is my boss's...god punishes us in strange ways. Anyways, i think that my problem is that it is having trouble with the creation of a new, blank file that will be called upon later. All of the text file open statements work in my program except where the file does not exist and it has to create one from scratch. This reasoning is what is making me believe this is the problem. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top