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

Creating a file

Status
Not open for further replies.

Adamba

IS-IT--Management
Aug 3, 2001
72
GB
[wavey]Hiya all

im using the vb function,

open "c:\Example.txt" for input as #1
write #1, "Example"
close #1

but if c:\example does not exsist it just crashes [cry]. how do i get it to create the file if it isnt there, this way i can write to variable filenames[licklips].

Thanks in advance [pc3]
Adam [glasses]
 
This is because you are opening the file for input (ie. for reading). You need to open the file for writing

try:

open "c:\Example.txt" for OUPUT as #1
write #1, "Example"
close #1

you should also use freefile to create the file handle as #1 might already be open:

dim FileHandle as long

FileHandle = freefile
open "c:\Example.txt" for OUPUT as FileHandle
write FileHandle, "Example"
close FileHandle

Hope this helps,

Chris Dukes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top