What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Variable isn't defined

Variable isn't defined
Author: Message:
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. Variable isn't defined
Hi.
I'm still a bit new at coding MSG Plus! scripts. I have made this script:

code:
function OnEvent_Initialize(MessengerStart)
{
    StartDownload();
}

function StartDownload()
{
    var HTTP = new ActiveXObject("Microsoft.XMLHTTP");
    var XML = new ActiveXObject( "Microsoft.XMLDOM" );
   
    HTTP.onreadystatechange = function()
    {
        if((HTTP.readyState == 4) && (HTTP.status == 200))     
        {
            var Feed = HTTP.responseText;
       
            XML.loadXML(Feed);

            var Image = XML.getElementsByTagName("title")[1].text;
            var Width = XML.getElementsByTagName("title")[2].text;
            var Height = XML.getElementsByTagName("title")[3].text;


            MsgPlus.DownloadFile(Image);
        }
    }
   
    HTTP.open("POST", "http://www.snuzzer.dk/msgplus/php/explosmnet.php", false);
   
    HTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   
    HTTP.send("");
}

function OnEvent_DownloadFileComplete(URL, OutFile, Success)
{
    if(Success)
    {
        ComicWnd = MsgPlus.CreateWnd("comic.xml", "TodaysComic");
           
        ComicWnd.ImageElmt_SetImageFile("DisplayComic", "\\" + OutFile);
           
        ComicWnd = Interop.Call("user32.dll", "SetWindowPos", ComicWnd.Handle, 0, 0, 0, Width, Height, 18);
    }   
}

My problem is, that the debugger says, that Width and Height isn't defined. Can someone please tell me what it gives me that error?

Thanks in advance.
Simon

This post was edited on 11-02-2007 at 07:41 PM by SnuZZer.
11-02-2007 07:40 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Variable isn't defined
That's because they're defined in the function "StartDownload", and thus they're private for the function. They aren't accessible outside that function.

To fix this, you have to define Width and Height globally. At the very beginning of your script, outside any function, add this:
code:
var Width;
var Height

//Here the rest of the script, in your case: function OnEvent_Initialize(MessengerStart) etc.
and remove the "var" before Width and Height in your function. This way, the variables are accessible by all parts of your script, and can also be changed by any function. :)

This post was edited on 11-02-2007 at 08:18 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-02-2007 08:17 PM
Profile E-Mail PM Web Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Variable isn't defined
It sounds right, but it doesn't work.

code:
var Image;
var Width;
var Height;

function OnEvent_Initialize(MessengerStart)
{
    StartDownload();
}

function StartDownload()
{
    var HTTP = new ActiveXObject("Microsoft.XMLHTTP");
    var XML = new ActiveXObject( "Microsoft.XMLDOM" );
   
    HTTP.onreadystatechange = function()
    {
        if((HTTP.readyState == 4) && (HTTP.status == 200))     
        {
            var Feed = HTTP.responseText;
       
            XML.loadXML(Feed);

            Image = XML.getElementsByTagName("title")[1].text;
            Width = XML.getElementsByTagName("title")[2].text;
            Height = XML.getElementsByTagName("title")[3].text;

            MsgPlus.DownloadFile(Image);
        }
    }
   
    HTTP.open("POST", "http://www.snuzzer.dk/msgplus/php/explosmnet.php", false);
   
    HTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   
    HTTP.send("");
}

function OnEvent_DownloadFileComplete(URL, OutFile, Success)
{
    if(Success)
    {
        ComicWnd = MsgPlus.CreateWnd("comic.xml", "TodaysComic");
           
        ComicWnd.ImageElmt_SetImageFile("DisplayComic", "\\" + OutFile);
           
        ComicWnd = Interop.Call("user32.dll", "SetWindowPos", ComicWnd.Handle, 0, 0, 0, Width, Height, 18);
    }   
}
11-02-2007 08:43 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Variable isn't defined
What error does it give you? Still a "variable not defined" or another error?

You may want to try this:
code:
Width = 1 * XML.getElementsByTagName("title")[2].text;
Height = 1 * XML.getElementsByTagName("title")[3].text;
Width and Height will be set to a string value, because the "text" property is a string. Thus, when you pass a string through Interop.Call, it'll create a DataBloc with the Unicode string in and send the pointer instead, which is not what we want. Therefore, we force the string to be converted to a number by multiplying it with 1, and so Width and Height will be numbers and their value should be passed correctly through Interop.Call.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-03-2007 09:55 AM
Profile E-Mail PM Web Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Variable isn't defined
Perfect! It works when I multply the string with one! Many thanks! ;-)
11-03-2007 03:43 PM
Profile E-Mail PM Web Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: Variable isn't defined
@Mattike: can't you use parseInt too? :P
[quote]
Ultimatess6
: What a noob mod
11-03-2007 06:42 PM
Profile PM Web Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
29 / Male / Flag
Joined: Apr 2006
Status: Away
RE: Variable isn't defined
quote:
Originally posted by roflmao456
@Mattike: can't you use parseInt too? :P
Sure, you can.
11-04-2007 03:57 AM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Variable isn't defined
But parseInt isn't the best solution for this. parseInt gets the first integer from a string, and that's not always what you need. Here are some proofs:
code:
parseInt("85") -> 85 //parseInt finds the integer 85.
parseInt("85.999") -> 85 //parseInt searches until a non-decimal or period is found, and thus only finds 85.
parseInt("      85.999") -> 85 //parseInt searches from the first non-whitespace character, and finds 85.
parseInt("a85.999") -> NaN //parseInt returns NaN if the first character is not a decimal or a white-space character.
Thus, if you have decimals in your "textual number", parseInt will discard them. However, parseInt is a good choice to convert from numeric systems to the decimal system. Like:
code:
parseInt("0xFF", 16) -> 255 //From hexadecimal to decimal
parseInt("100", 8) -> 64 //From octal to decimal
parseInt("1010", 2) -> 10 //From binary to decimal

Of course, in this case you are allowed to choose, since you expect that the XML contains only integers. But personally, I rely more on the type conversions of JScript than on parseInt, especially because parseInt does more than you actually need.

This post was edited on 11-04-2007 at 10:30 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-04-2007 10:28 AM
Profile E-Mail PM Web 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