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

saving to disk 1

Status
Not open for further replies.

chrisfaye

Technical User
May 10, 2001
4
GB
I am trying to save todisk without any success, i am, not shure of the procedure or the code can any one help.
 
Add a Project / Reference to the Microsoft Scripting Runtime if you want "As Scripting." intellosense else use As object.
Code:
Dim fs as Scripting.FileSystemObject
Dim a as Scripting.TextStream
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("This is a test.")
a.Close
 
You can write to a file without using the Scripting Object.

VB supports Open, Print #, Close, and Freefile.

Dim F as Long, OutFile as String
F = Freefile
OutFile = <File Name with or without Path, as String>

Open OutFile For Output As #F
Print #F, <Output as String>
Close #F

The above code is throwback to the earliest versions of BASIC that I can remember. Still works though.
 
If you like more the API, and you want some extra functionality you should declare and use the CreateFile API function.

You will be able to create self deleting files, files that will be created in the system temp direcctory and other options that the VB does't currently offer.
And I guarantee to you it is very fast.

The Declare body and required constants for the CreateFile function you should take from the VB add-in VB API Viewer. You can find also some examples in MSDN if you like copy/paste or you are in a hurry.

Hope of being of some help, s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top