Interactive PowerBasic Forum

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Windows Script Runtime => Source Code => Scripting => FileSystemObject => Topic started by: José Roca on July 13, 2008, 11:21:38 PM

Title: ITextStream.Write Method
Post by: José Roca on July 13, 2008, 11:21:38 PM


The following example illustrates the use of the Write method.

JScript


function WriteToFile()
{
   var fso, f, r
   var ForReading = 1, ForWriting = 2;
   fso = new ActiveXObject("Scripting.FileSystemObject")
   f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true)
   f.Write("Hello world!");
   f.Close();
   f = fso.OpenTextFile("c:\\testfile.txt", ForReading);
   r = f.ReadLine();
   return(r);
}


VBScript


Function WriteToFile
   Const ForReading = 1, ForWriting = 2
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
   f.Write "Hello world!"
   Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
   WriteToFile = f.ReadLine
End Function


PowerBASIC


FUNCTION WriteToFile () AS STRING

   LOCAL fso AS IFileSystem
   LOCAL f AS ITextStream

   fso = NEWCOM ("Scripting.FileSystemObject")
   f = fso.OpenTextFile(UCODE$("c:\testfile.txt"), %IOMode_ForWriting, %VARIANT_TRUE)
   f.Write UCODE$("Hello world!")
   f.Close
   f = fso.OpenTextFile(UCODE$("c:\testfile.txt"), %IOMode_ForReading)
   FUNCTION = ACODE$(f.ReadLine)
   f.Close

END FUNCTION