What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] Save strings

[Help] Save strings
Author: Message:
Anton
New Member
*


Posts: 12
30 / Male / –
Joined: Aug 2006
O.P. Huh?  [Help] Save strings
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
08-03-2006 04:38 PM
Profile PM Find Quote Report
Huhu_Manix
Full Member
***

Avatar
Upload me again... *salivate*

Posts: 106
– / Male / –
Joined: Jul 2006
RE: [Help] Save strings
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();
}
08-03-2006 06:24 PM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: [Help] Save strings
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);
}

[Image: 1-0.png]
             
08-03-2006 07:36 PM
Profile PM Web Find Quote Report
Anton
New Member
*


Posts: 12
30 / Male / –
Joined: Aug 2006
O.P. RE: RE: [Help] Save strings
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?
08-04-2006 01:50 PM
Profile PM Find Quote Report
Huhu_Manix
Full Member
***

Avatar
Upload me again... *salivate*

Posts: 106
– / Male / –
Joined: Jul 2006
RE: [Help] Save strings
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 ;
}
08-04-2006 01:56 PM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [Help] Save strings
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.
[Image: spartaafk.png]
08-04-2006 01:58 PM
Profile PM Web Find Quote Report
Anton
New Member
*


Posts: 12
30 / Male / –
Joined: Aug 2006
O.P. RE: [Help] Save strings
Ok. Thanks. :) I shell test it when I get home.
08-04-2006 02:38 PM
Profile PM Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: [Help] Save strings
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;
}



This post was edited on 08-04-2006 at 03:16 PM by -dt-.
[Image: dt2.0v2.png]      Happy Birthday, WDZ
08-04-2006 03:13 PM
Profile PM Web Find Quote Report
Anton
New Member
*


Posts: 12
30 / Male / –
Joined: Aug 2006
O.P. RE: [Help] Save strings
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...:$
08-08-2006 07:16 PM
Profile PM Find Quote Report
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
36 / Male / Flag
Joined: Jul 2006
RE: [Help] Save strings
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);
}

My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
08-08-2006 08:19 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On