ReportNode4.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.
// Txtcreate.js - A JScript
// ReportNode4.txt is a Text File used for report data
// First, test if ReportNode4.txt file exists,
// then enter a row of time stamped data.
// if not, create it with header lines.
var fso, f, s, filename, ForWriting, ForAppending, OldFile, NewFile, LineofText;
s = "", ForWriting = 2, ForAppending = 8;
filename = "ReportNode4.txt";
// Test if file exists
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(filename)) {
// Use the WriteLine method to write a newline character or a string that ends with a newline character.
OldFile = fso.OpenTextFile(filename, ForAppending, false);
LineofText = GETVAL("%TTMDATE") + " " + GETVAL("%TTMTIME") + " " + GETVAL("AMPLITUDE") + " " + GETVAL("TIMER");
OldFile.WriteLine(LineofText);
OldFile.Close();
}
else
{
// Create the file since it doesn't exist
// option false is do not overwrite file if it exists, which it shouldn't
// and the false option is CASE SENSITIVE
NewFile = fso.CreateTextFile(filename, false);
// add a header
NewFile.WriteLine("----- Power Usage Report------- Page 1");
NewFile.WriteLine("Date-------Time-------Amplitude-----Timer----");
// write WebAccess tag data
LineofText = GETVAL("%TTMDATE") + " " + GETVAL("%TTMTIME") + " " + GETVAL("AMPLITUDE") + " " + GETVAL("TIMER");
NewFile.WriteLine(LineofText);
NewFile.Close();
}
// JScript Help has more information on working with files at:
// MSDN Home > MSDN Library > Web Development > Scripting > Windows Script Technologies > Script Runtime > FileSystemObject Object > FileSystemObject Basics
// http://msdn.microsoft.com/library/en-us/script56/html/sgWorkingWithFiles.asp