[Help] Save strings |
Author: |
Message: |
Anton
New Member
Posts: 12
30 / / –
Joined: Aug 2006
|
O.P. [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 . And I need it to a count down script. Sorry my bad English.
//Anton
|
|
08-03-2006 04:38 PM |
|
|
Huhu_Manix
Full Member
Upload me again... *salivate*
Posts: 106
– / / –
Joined: Jul 2006
|
RE: [Help] Save strings
Write the string in a file...
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 |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
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);
}
|
|
08-03-2006 07:36 PM |
|
|
Anton
New Member
Posts: 12
30 / / –
Joined: Aug 2006
|
O.P. RE: RE: [Help] Save strings
quote: Originally posted by Huhu_Manix
Write the string in a file...
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 |
|
|
Huhu_Manix
Full Member
Upload me again... *salivate*
Posts: 106
– / / –
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 |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
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.
|
|
08-04-2006 01:58 PM |
|
|
Anton
New Member
Posts: 12
30 / / –
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 |
|
|
-dt-
Scripting Contest Winner
;o
Posts: 1819 Reputation: 74
36 / /
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-.
Happy Birthday, WDZ
|
|
08-04-2006 03:13 PM |
|
|
Anton
New Member
Posts: 12
30 / / –
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 |
|
|
Shondoit
Full Member
Hmm, Just Me...
Posts: 227 Reputation: 15
36 / /
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);
}
|
|
08-08-2006 08:19 PM |
|
|
|