Shoutbox

A newbie question - 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: A newbie question (/showthread.php?tid=92096)

A newbie question by chrisb on 09-03-2009 at 10:58 AM

I have a question regarding the ability to read text files, I have a text file however I am getting the error

code:
Function called: OnEvent_MyStatusChange
Error: Bad file name or number (code: -2146828236)
       File: my.js. Line: 11.
Function OnEvent_MyStatusChange returned an error. Code: -2147352567

And the code I am using is

code:
function OnEvent_MyStatusChange()    {
Messenger.MyPersonalMessage = new ActiveXObject  ( 'Scripting.FileSystemObject' ).OpenTextFile ( 'http://buttonbashers.co.uk/test.txt' , 1 ).ReadAll ( );
}

RE: A newbie question by matty on 09-03-2009 at 12:19 PM

FileSystemObject can only read local files. Therefore you have 2 options. Firstly you can use URLDownloadToFile to download the text file and then you can read it locally. Second option is to use ajax, an example can be found here -dt-'s reply to Tips.


RE: A newbie question by chrisb on 09-03-2009 at 02:43 PM

i went for the AJAX option, thanks! I also wanted to know, how do I create the option windows such as for setting variables?


RE: A newbie question by matty on 09-03-2009 at 03:00 PM

Take a look at the scripting document. It provides examples. They are made in XML.


RE: A newbie question by chrisb on 09-03-2009 at 03:28 PM

Okay i have found that now, one last question. How can I store information such as a perticular variable so that it is remembered for next time. I can't seem to find it in the documentation.


RE: A newbie question by matty on 09-03-2009 at 03:32 PM

There isn't a defined way. The developer can decide how they want to do that. Could be any of the following and then some:

  • INI File
  • XML File
  • Registry
  • Database

That is all up to you as the developer.
RE: A newbie question by chrisb on 09-03-2009 at 03:34 PM

Oh wow, such choice :P, I will take a look in the jScript documentation for that. Thanks a bunch matty, you have been a big help!


RE: A newbie question by chrisb on 09-03-2009 at 03:45 PM

Could you just tell me what the following should be, I know I have done it wrong...

var ctrlTxt = MsgPlus.GetControlText("txtEl");


RE: A newbie question by matty on 09-03-2009 at 03:48 PM

quote:
Originally posted by chrisb
Oh wow, such choice :P, I will take a look in the jScript documentation for that. Thanks a bunch matty, you have been a big help!
The JScript documentation won't give you all the information you need.
I attached a registry script I wrote for easy access to the registry.
A database is just too much work for a script and not worth the effort. This leaves you with XML and INI files.
INI files use the following functions:
GetPrivateProfileString
WritePrivateProfileString
GetPrivateProfileInt

As for XML there is lots of information out on the internet about it.

quote:
Originally posted by chrisb
Could you just tell me what the following should be, I know I have done it wrong...

var ctrlTxt = MsgPlus.GetControlText("txtEl");
GetControlText is a function of the Plus! Window. Therefore when you open the window you need to assign it to a variable for later use.

The following is simply an example and shouldn't be used for larger scripts with multiple windows
js code:
var pPlusWnd;
pPlusWnd = MsgPlus.OpenWindow ( '...' , '...' );
Debug.Trace ( pPlusWnd.GetControlText ( 'myControl' ) );

RE: A newbie question by chrisb on 09-03-2009 at 03:50 PM

Thanks, that worked :)


RE: A newbie question by chrisb on 09-03-2009 at 04:11 PM

function OnEvent_Timer("getTweets")    {
Messenger.MyPersonalMessage = Math.random();
}

Why is that not working?


RE: A newbie question by chrisb on 09-03-2009 at 04:37 PM

MsgPlus.AddTimer("getTweets", 5000)


RE: A newbie question by Matti on 09-03-2009 at 05:00 PM

quote:
Originally posted by chrisb
function OnEvent_Timer("getTweets")    {
Messenger.MyPersonalMessage = Math.random();
}

Why is that not working?
A function definition has the following form:
js code:
function functionName(paramName1, paramName2) {
    // code goes here
}
The error in your code is that you're giving a value instead of a variable name where your parameters go. This is faulty programming logic and therefore invalid JScript and should be corrected like so:
js code:
function OnEvent_Timer(timerID) {
    if(timerID === "getTweets") {
        Messenger.MyPersonalMessage = Math.random();
    }
}
  1. The function receives its parameters and assigns the first parameter value to the variable "timerID".
  2. The "timerID" is checked against a string, to verify we're handling the right timer.
  3. When the "timerID" is checked, the personal message is set.
For more information, visit W3Schools - JavaScript functions.
RE: A newbie question by chrisb on 09-03-2009 at 05:04 PM

Error: 'timerID' is undefined (code: -2146823279)
       File: file.js. Line: 22.
Function OnEvent_Timer returned an error. Code: -2147352567

I get this?


RE: A newbie question by chrisb on 09-03-2009 at 05:06 PM

Oh I got why not :), false alarm. Thanks


RE: A newbie question by chrisb on 09-05-2009 at 04:25 PM

I can't seem to find how to do an ini file save and load, could you give me an example?