quote:
Originally posted by Spunky
Although I'm sure there should be an f.Close(); before the return. This is taken from MSDN though
Indeed there should. It wouldn't be the first time some info or code on the MSDN Library is faulty. This said, at least all the complete function examples on the MSDN Library overview page in regards to reading/writing files do include the Close() statement.
------------
quote:
Originally posted by Infinity8888
this wasn't discussed in the messenger plus documentation.
Because the
Messenger Plus! Scripting documentation help file (or the
online docs) is about... well... Messenger Plus! stuff. It is specifically about Plus! objects, Plus! functions and Plus! events in the integrated scripting language. All the other normal things you could do in JScript are out of scope of this documentation.
So, writing to files and all kind of other stuff is pure JScript and nothing todo with Plus! specifically and thus you'll find info about that in the
Windows Scripting Documentation help file (or
online docs) instead.
There you'll find example code as posted by Spunky. Although, there are some small errors in Spunky's code. Below, the fixed lines in yellow:
Javascript code:
function Write(filename, text){
try{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename, 2, true); f.Write(text);
f.Close();
return 1;
}catch(e){
Debug.Trace("Write Error: (File '"+filename+"': " + e.message);
return 0;
}
}
function Read(filename){ try{
var fso = new ActiveXObject("Scripting.FileSystemObject"); var f = fso.OpenTextFile(filename, 1); var r = f.ReadLine(); f.Close(); return r; }catch(e){
Debug.Trace("Read Error: (File '"+filename+"': " + e.message);
return 0; // Failed
}
}