Shoutbox

[Help] Save strings - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help] Save strings (/showthread.php?tid=64421)

[Help] Save strings by Anton on 08-03-2006 at 04:38 PM

Hi!
I wonder how I can save a string with a script that is saved on the computer, so the script can remember the string, even if I close WLM. Can someody tell me how? I think it is very easy, but I canīt find the answer :S. And I need it to a count down script. Sorry my bad English.
//Anton


RE: [Help] Save strings by Huhu_Manix on 08-03-2006 at 06:24 PM

Write the string in a file... ^o)

code:
function writeFile(fichier, txt){
    var Object = new ActiveXObject('Scripting.FileSystemObject');
     var NouvTxt = Object.CreateTextFile(fichier,true);
    NouvTxt.Write(txt);
    NouvTxt.Close();
}

RE: [Help] Save strings by Ezra on 08-03-2006 at 07:36 PM

or you use the registry.

Easy, multi-user and will be automaticly deleted when the script is removed. (A file in the scripts directory will be deleted too)

code:
function WriteRegistry(key, value)
{
  var Shell = new ActiveXObject("WScript.Shell");
  return Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key, value, "REG_SZ");
}

function ReadRegistry(key)
{
  var Shell = new ActiveXObject("WScript.Shell");
  return Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key);
}

function RemoveRegistry(key)
{
  var Shell = new ActiveXObject("Wscript.Shell");
  return Shell.RegDelete(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key);
}


RE: RE: [Help] Save strings by Anton on 08-04-2006 at 01:50 PM

quote:
Originally posted by Huhu_Manix
Write the string in a file... ^o)

code:
function writeFile(fichier, txt){
    var Object = new ActiveXObject('Scripting.FileSystemObject');
     var NouvTxt = Object.CreateTextFile(fichier,true);
    NouvTxt.Write(txt);
    NouvTxt.Close();
}


Thanks for the answers! But if I want to write the string in a file, how do I do to read it again?
RE: [Help] Save strings by Huhu_Manix on 08-04-2006 at 01:56 PM

Oooh you want to read the file too...it's not important ! ^^'

Take this but i think there's better function than this :

code:
function read(file) {
    var FileSystem= new ActiveXObject('Scripting.FileSystemObject');
    var file = FileSystem.OpenTextFile(file, 1); 
        lines = "";
        while(!file.AtEndOfStream) {
            lines += file.ReadLine()+"\n";
        }
    file.Close();
    return lines ;
}

RE: [Help] Save strings by RaceProUK on 08-04-2006 at 01:58 PM

Somehow I doubt it's simpler than that. At least you don't have to use Interop and call the APIs like CreateFile and ReadFile, which would just get annoying.


RE: [Help] Save strings by Anton on 08-04-2006 at 02:38 PM

Ok. Thanks. :) I shell test it when I get home.


RE: [Help] Save strings by -dt- on 08-04-2006 at 03:13 PM

quote:
Originally posted by Huhu_Manix
Oooh you want to read the file too...it's not important ! ^^'

Take this but i think there's better function than this :

code:
function read(file) {
    var FileSystem= new ActiveXObject('Scripting.FileSystemObject');
    var file = FileSystem.OpenTextFile(file, 1); 
        lines = "";
        while(!file.AtEndOfStream) {
            lines += file.ReadLine()+"\n";
        }
    file.Close();
    return lines ;
}


code:
function readFile(file, isUnicode){
    var fileStream = new ActiveXObject('Scripting.FileSystemObject').GetFile(file).OpenAsTextStream(1,((typeof(isUnicode) != "undefined" && isUnicode) ? -1 : 0));
    var data = fileStream.ReadAll();
    fileStream.Close();
    return data;
}



RE: [Help] Save strings by Anton on 08-08-2006 at 07:16 PM

It works!:) But I have a new problem. If I try to read a file that not exists, it will be an error. Is there some way to check if the file exists or not. This is a big problem, becouse, noone will exist when I start the script the first time. And I canīt find a way to create the files without changing the string in the files that alredy exists! Can somebody help me?
Again, sorry my bad English...:$


RE: [Help] Save strings by Shondoit on 08-08-2006 at 08:19 PM

Personaly, I work most with the registry, when you use a per user setting, your script directory will become quite full

This works better, imo
When you call ReadRegistry and the key does not exist, it will write the initvalue to the registry
That way you can give start string when your script runs for the first time

code:
function WriteRegistry (key, value) {
  var Shell = new ActiveXObject("WScript.Shell");
    return Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + key, value, "REG_SZ");
}

function ReadRegistry (key) {
  var Shell = new ActiveXObject("WScript.Shell");
  try {
    return Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + key);
  } catch (e) {
    WriteRegistry(key, initvalue);
    return initvalue;
  }
}

function RemoveRegistry (key) {
  var Shell = new ActiveXObject("Wscript.Shell");
  return Shell.RegDelete(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + key);
}