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

File I/O using VB Script ??

Status
Not open for further replies.

MRSOLO

Technical User
Jan 28, 2003
31
IE

I am writing some Vb script at the moment where I want to output to file some of the variables that result in errors.

I am using standard vb6 File I/O code for sequential files

e.g. Open "C:\ADUserError.txt" for append As #1

but it gives a compilation error on this line as follows:

Char :27
Error : Expected end of statement.

Can someone advise if File I/O is possible using VB Script.

Thanks

 
Hello MSSOLO,

Decidely you need some adaptation to a purely late-binding scripting language. The following is an example from vbs documentation of the FileSystemOhject OpenTextFiles method slightly modified to reflect your concern:

Code:
Sub OpenTextFileADUserError
   Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile("C:\ADUserError.txt", ForAppending)
   f.Write "New error information to append..."
   f.Close
End Sub

Complete detail, I'm afraid you have to consult the documentation. The adapation cannot be done by guessing.

regards - tsuji
 
Here is some easy code to write a file.
Enjoy Bob

DIM fso,txt01
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt01 = fso.CreateTextFile("c:\text.txt", True)

txt01.WriteLine("Text")
txt01.WriteLine("More text")

txt01.Close

MsgBox "File Created!",vbInformation,"Create a text file"

Wscript.Quit
 
MRSOLO,

Sorry for the mistyped handle.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top