12.17.14          Write data to a Text file - VB Script

ReportNode3.txt is a Text File used for report data. The script first runs a Test if the file exists.  If not, create it with header lines, then enter a row of time stamped data.


Rem Txtcreate.vbs - A VB Script

Rem ReportNode3.txt is a Text File used for report data

Rem First, test if ReportNode3.txt files exists,

Rem  then enter a row of time stamped data.

Rem if not, create it with header lines.

Dim fso, filename

   Set fso = CreateObject("Scripting.FileSystemObject")

   filename ="ReportNode3.txt"

   If (fso.FileExists(filename)) Then

      Rem BWSPOOL filename & " exists."

      Rem Specified strings are written to the file with no intervening spaces or characters between each string.

      Rem Use the WriteLine method to write a newline character or a string that ends with a newline character.

      Const ForReading = 1, ForWriting = 2, ForAppending = 8

      Dim Oldfile

      Set Oldfile = fso.OpenTextFile(filename, ForAppending, False)

      OldFile.WriteLine( GETVAL("%TTMDATE") & " " & GETVAL("%TTMTIME") & "  " & GETVAL("AMPLITUDE") & "       " & GETVAL("TIMER") )



      Rem BWSPOOL filename & " doesn't exist. New file created."

      Dim NewFile

      Rem option false is do not overwrite file if it exists, which it shouldn't

      Set NewFile = fso.CreateTextFile(filename, False)

      NewFile.WriteLine("----- Power Usage Report------- Page 1")


      NewFile.WriteLine( GETVAL("%TTMDATE") & " " & GETVAL("%TTMTIME") & "  " & GETVAL("AMPLITUDE") & "       " & GETVAL("TIMER") )


   End If


Rem VB Help has more information on working with files at:

Rem  MSDN Home >  MSDN Library >  Web Development >  Scripting >  Windows Script Technologies >  Script Runtime >  FileSystemObject Object >  FileSystemObject Basics

Rem http://msdn.microsoft.com/library/en-us/script56/html/sgWorkingWithFiles.asp