Shoutbox

How do I save data????? - 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: How do I save data????? (/showthread.php?tid=97911)

How do I save data????? by Infinity8888 on 07-01-2011 at 12:23 PM

Hello Everyone

I've been wanting to develop a script of my own for over 6 months now but I found it very hard to save data on the hard drive. In fact, I still don't know how it works. I know it has to do with XML and ActiveX but I never used both these languages.

So basically, my question is : what is the simplest way to save something on the hard drive??? I spend my whole afternoon yesterday and today's whole morning trying to figure out how it worked, but it seems hard and complicated. Is there simply a function that does the work?

Also, I suck at JScript

Please reply, thank you


RE: How do I save data????? by matty on 07-01-2011 at 12:44 PM

What exactly are you trying to save?


RE: How do I save data????? by Infinity8888 on 07-01-2011 at 10:56 PM

I wanna make a script that counts how many times I spoke to a contact. I need to save that number every time I close the chat window let's say


RE: How do I save data????? by Carol6Sweet on 07-02-2011 at 01:13 PM

I am interested in knowing the code so if you get it from anywhere please share.


RE: How do I save data????? by Infinity8888 on 07-02-2011 at 03:51 PM

There's no code for the moment. I programmed my app on MatLab, and generated an exe file. But it sucks to have to write the name of the person everytime, so that's why I wanna do it as a messenger script.
The problem is I don't know how to save the data


RE: How do I save data????? by MeEtc on 07-02-2011 at 05:28 PM

There are 2 ways that you can do this, you can save data to a file or to the Windows registry. Take a look on the scripts forum and other scripts


RE: How do I save data????? by Spunky on 07-02-2011 at 06:11 PM

quote:
Originally posted by Infinity8888
I wanna make a script that counts how many times I spoke to a contact. I need to save that number every time I close the chat window let's say

How many messages or how many times a window was opened?
RE: How do I save data????? by Infinity8888 on 07-02-2011 at 06:19 PM

How many times a window was opened for example. The algorithm is simple - as I said I've already done it all in Matlab - I just don't know how to save data with jscript, and this wasn't discussed in the messenger plus documentation. Is it just a simple instruction?

I've checked out another script (called Stat Center) and it was really confusing, there were notions of encoder, decoder, serializer, asyncrhonous, I was like "wtf???"


RE: How do I save data????? by Spunky on 07-02-2011 at 06:51 PM

The best analogue I can think of to learn from would be a win32 read/write example. Some things need to be changed though still such as ActiveXObject instead of create object and no constants are defined so you have to explicitly assign these values. There may be an example somewhere around here. I'll see what I can dig up (getting son to sleep atm)


js code:
function WriteDemo()
{
   var fso, f, r
   var ForReading = 1, ForWriting = 2;
   fso = new ActiveXObject("Scripting.FileSystemObject")
   f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true)
   f.Write("Hello world!");
   f.Close();
   f = fso.OpenTextFile("c:\\testfile.txt", ForReading);
   r = f.ReadLine();
   return(r);
}

Hopefully you can use bits of that for what you want; it's all there


Although I'm sure there should be an f.Close(); before the return. This is taken from MSDN though


It can be put into two functions:

js code:
function Write(filename, text){
   try{
      var fso = new ActiveXObject("Scripting.FileSystemObject")
      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{
      f = fso.OpenTextFile(filename, 1);
      return f.ReadLine();
   }catch(e){
      Debug.Trace("Read Error: (File '"+filename+"': " + e.message);
      return 0; // Failed
   }
}

RE: How do I save data????? by Infinity8888 on 07-02-2011 at 08:59 PM

Oh thanx this is working. I've read about XML but if I can use this to write in txt files, it doesn't bother me

Thank you very much


RE: RE: How do I save data????? by CookieRevised on 07-02-2011 at 10:43 PM

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:
js 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
   }
}


;)
RE: How do I save data????? by Spunky on 07-02-2011 at 11:48 PM

quote:
Originally posted by CookieRevised
Although, there are some small errors in Spunky's code

Damn, was in a rush :p Good to know that the Close() was needed though (Y)
RE: How do I save data????? by Infinity8888 on 07-03-2011 at 05:22 PM

Yeah I added the Close() yesterday because I wasn't able to erase the files I was working with because they were still used by messenger.

I just needed something to start with. Thank you very much