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

Open (input, write..bla bla) on files that dont exist yet?

Status
Not open for further replies.

DJKAOS

Technical User
Jun 30, 2000
101
US
I'm trying to store/save some info in files..but if
the file doesn't exist yet then when I do,

Open "test.txt" for input as #1

gives me an error if test.txt doesn't exist...in C++ the open command creates the file if its not already there..how do I do this in VB?

Thanks, its probably simple but I cant get it to work..the
help files say that if you set it to Append, Binary, Output, or Random it will create a new file if it doesn't exist.. I tried Open "test.txt" for output as #1 and still got a pathname crash.
 
Hiya,

You're in the MS Access forum mate - you might get advice, but it would defeat the object of a library of topical threads and defeat the point of this site.

You may have got here because of a VBA reference - that's VB for Access.

Specific VB has it's own forum.

In the 'Search box' above type 'VB' make sure that the 'Find a Forum' is checked and click the [Go] button.

When you get there, do a search for your problem (before you post) - it MUST be already in there - it's common.

Regards,

Darrylle

"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Perhaps you are looking for the open as text stream method. Something along the lines of:

Sub TextStreamTest
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile "test1.txt" 'Create a file
Set f = fs.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write "Hello World"
ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
s = ts.ReadLine
MsgBox s
ts.Close
End Sub

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Thanks, I don't think thats what I'm looking for..but it might work. I have everything working right now but it crashes if the filename I try to open doesn't exist...so to solve it I just manually create the file with notepad first...which wont work in the long run when files need to be made on the fly.

And I know this is the MS Access forumn..I am working on a database, I just need some VB help with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top