PowerBasic Museum 2020-A

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:52:41 PM

Title: ITextStream.AtEndOfStream Property
Post by: José Roca on July 13, 2008, 11:52:41 PM


The following example illustrates the use of the AtEndOfStream property.

JScript


function ReadEntireFile(filespec)
{
   var fso, f, s, ForReading;
   ForReading = 1, s = "";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.OpenTextFile(filespec, ForReading, false);
   while (!f.AtEndOfStream)
      s += f.ReadLine( );
   f.Close( );
   return(s);
}


VBScript


Function ReadEntireFile(filespec)
   Const ForReading = 1
   Dim fso, theFile, retstring
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set theFile = fso.OpenTextFile(filespec, ForReading, False)
   Do While theFile.AtEndOfStream <> True
      retstring = restring & theFile.ReadLine
   Loop
   theFile.Close
   ReadEntireFile = retstring
End Function


PowerBASIC


SUB ReadEntireFile (BYVAL strFileSpec AS STRING)

   LOCAL fso AS IFileSystem
   LOCAL theFile AS ITextStream
   LOCAL restring AS STRING

   fso = NEWCOM ("Scripting.FileSystemObject")
   theFile = fso.OpenTextFile(UCODE$(strFileSpec), %IOMode_ForReading, %VARIANT_FALSE)
   DO
      IF theFile.AtEndOfStream THEN EXIT DO
      restring = retstring & theFile.ReadLine
   LOOP
   theFile.Close
   FUNCTION = restring

END SUB