Shoutbox

Button_SetCheckState problem - 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: Button_SetCheckState problem (/showthread.php?tid=82303)

Button_SetCheckState problem by WarPenguin on 03-12-2008 at 05:41 PM

hi everyone,

Im writing a script that has an options dialog to configure some of its functions. For that purpose im using checkboxes. I wanted the script to read the configurations from a file and set the checkboxes accordingly.
But it gives me this error:

Error: Object doesn't support this property or method (code: -2146827850)

Here is the code:

if(newfile.Readline() == 1){
optionsWnd.Button_SetCheckState("Abreum",true);
}else{
optionsWnd.Button_SetCheckState("Abreum",false);
}

Thanks.


RE: Button_SetCheckState problem by Spunky on 03-12-2008 at 05:47 PM

Which one of those lines is mentioned in the debug window? The Button_SetCheckState() appears ok at first glance


RE: Button_SetCheckState problem by WarPenguin on 03-12-2008 at 05:57 PM

This one:
optionsWnd.Button_SetCheckState("Abreum",true);


RE: Button_SetCheckState problem by matty on 03-12-2008 at 05:58 PM

Can you post the entire js file. It may be that optionsWnd is null or not PlusWnd object.


RE: Button_SetCheckState problem by WarPenguin on 03-12-2008 at 06:00 PM

Thats what I thought first but I've played around with it, and Im sure thats not the problem.


RE: Button_SetCheckState problem by matty on 03-12-2008 at 06:01 PM

quote:
Originally posted by WarPenguin
Thats what I thought first but I've played around with it, and Im sure thats not the problem.
Then before the if statement that you posted above put in

Debug.Trace(typeof optionsWnd);
Debug.Trace(optionsWnd.Handle);

Post with the debug results from that.
RE: Button_SetCheckState problem by WarPenguin on 03-12-2008 at 06:05 PM

This is the result:

string

Error: Object doesn't support this property or method (code: -2146827850)


RE: Button_SetCheckState problem by matty on 03-12-2008 at 06:06 PM

Ok so optionsWnd should be an object not a string.

Post your code I will see what you did wrong.


RE: Button_SetCheckState problem by WarPenguin on 03-12-2008 at 06:10 PM

Here it is:

var AbreUm;
var AbreDois;
var AbreTres;
var SignIn;
var SignOut;
var Sound;

...(This functions have nothing to do with the options)

function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd){
if(MenuItemId == "About"){
MsgPlus.CreateWnd("about.xml", "about");
}

if(MenuItemId == "Options"){
MsgPlus.CreateWnd("options.xml", "options");
ReadSettings("options");
}

}

function WriteSettings(PlusWnd){

Debug.Trace("Writing settings to file...");
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CreateTextFile(MsgPlus.ScriptFilesPath + "\\Settings.txt",true);
var newfile = fso.OpenTextFile(MsgPlus.ScriptFilesPath + "\\Settings.txt",8,true);

if(PlusWnd.Button_IsChecked("Abreum") == true){
newfile.WriteLine("1");
}else{
newfile.WriteLine("0");
}

if(PlusWnd.Button_IsChecked("Abredois") == true){
newfile.WriteLine("1");
}else{
newfile.WriteLine("0");
}

if(PlusWnd.Button_IsChecked("Abretres") == true){
newfile.WriteLine("1");
}else{
newfile.WriteLine("0");
}

if(PlusWnd.Button_IsChecked("signIn") == true){
newfile.WriteLine("1");
}else{
newfile.WriteLine("0");
}

if(PlusWnd.Button_IsChecked("sound") == true){
newfile.WriteLine("1");
}else{
newfile.WriteLine("0");
}

if(PlusWnd.Button_IsChecked("signOut") == true){
newfile.WriteLine("1");
}else{
newfile.WriteLine("0");
}

newfile.Close();
}

function OnOptionsEvent_CtrlClicked(PlusWnd, ControlId){
if(ControlId == "BtnCancel"){
PlusWnd.Close(2);
}
if(ControlId == "OK"){
WriteSettings(PlusWnd);
PlusWnd.Close(1);
}
}

function ReadSettings(optionsWnd){
Debug.Trace("Reading settings from file...");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newfile = fso.OpenTextFile(MsgPlus.ScriptFilesPath + "\\Settings.txt",1,true);

Debug.Trace(typeof optionsWnd);
Debug.Trace(optionsWnd.Handle);
if(newfile.Readline() == 1){
AbreUm = true;
optionsWnd.Button_SetCheckState("Abreum",AbreUm);
}else{
AbreUm = false;
optionsWnd.Button_SetCheckState("Abreum",AbreUm);
}

if(newfile.Readline() == 1){
AbreDois = true;
optionsWnd.Button_SetCheckState("Abredois",AbreDois);
}else{
AbreDois = false;
optionsWnd.Button_SetCheckState("Abredois",AbreDois);
}

if(newfile.Readline() == 1){
AbreTres = true;
optionsWnd.Button_SetCheckState("Abretres",AbreTres);
}else{
AbreTres = false;
optionsWnd.Button_SetCheckState("Abretres",AbreTres);
}

if(newfile.Readline() == 1){
SignIn = true;
optionsWnd.Button_SetCheckState("signIn",SignIn);
}else{
SignIn = false;
optionsWnd.Button_SetCheckState("signIn",SignIn);
}

if(newfile.Readline() == 1){
Sound = true;
optionsWnd.Button_SetCheckState("sound", Sound);
}else{
Sound = false;
optionsWnd.Button_SetCheckState("sound", Sound);
}

if(newfile.Readline() == 1){
SignOut = true;
optionsWnd.Button_SetCheckState("signOut", SignOut);
}else{
SignOut = false;
optionsWnd.Button_SetCheckState("signOut", SignOut);
}
newfile.Close();
}


RE: Button_SetCheckState problem by matty on 03-12-2008 at 06:15 PM

Your original function

code:
function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd){
if(MenuItemId == "About"){
MsgPlus.CreateWnd("about.xml", "about");
}

if(MenuItemId == "Options"){
MsgPlus.CreateWnd("options.xml", "options");
ReadSettings("options");
}
You are passing a string as the window object.

code:
function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd){
    if(MenuItemId == "About"){
        MsgPlus.CreateWnd("about.xml", "about");
    }
    else if(MenuItemId == "Options"){
        var optionsWnd = MsgPlus.CreateWnd("options.xml", "options");
        ReadSettings(optionsWnd);
    }
}

This code passes the window object.

Alternately you can do this

code:
function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd){
    if(MenuItemId == "About"){
        MsgPlus.CreateWnd("about.xml", "about");
    }
    else if(MenuItemId == "Options"){
        ReadSettings(MsgPlus.CreateWnd("options.xml", "options"));
    }
}



Also your read settings function can be altered

code:
function ReadSettings(optionsWnd){
    Debug.Trace("Reading settings from file...");
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var newfile = fso.OpenTextFile(MsgPlus.ScriptFilesPath + "\\Settings.txt",1,true);
   
    optionsWnd.Button_SetCheckState("Abreum", (newfile.Readline() == 1 ? true : false));
    optionsWnd.Button_SetCheckState("Abredois",(newfile.Readline() == 1 ? true : false));
    optionsWnd.Button_SetCheckState("Abretres",(newfile.Readline() == 1 ? true : false));
    optionsWnd.Button_SetCheckState("signIn",(newfile.Readline() == 1 ? true : false));
    optionsWnd.Button_SetCheckState("sound", (newfile.Readline() == 1 ? true : false));
    optionsWnd.Button_SetCheckState("signOut",(newfile.Readline() == 1 ? true : false));
   
    newfile.Close();
}

code:
function WriteSettings(PlusWnd){
    Debug.Trace("Writing settings to file...");
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.CreateTextFile(MsgPlus.ScriptFilesPath + "\\Settings.txt",true);
    var newfile = fso.OpenTextFile(MsgPlus.ScriptFilesPath + "\\Settings.txt",8,true);

    newfile.WriteLine(PlusWnd.Button_IsChecked("Abreum"));
    newfile.WriteLine(PlusWnd.Button_IsChecked("Abredois"));
    newfile.WriteLine(PlusWnd.Button_IsChecked("Abretres");
    newfile.WriteLine(PlusWnd.Button_IsChecked("signIn"));
    newfile.WriteLine(PlusWnd.Button_IsChecked("sound"));teLine(PlusWnd.Button_IsChecked("signOut"));

    newfile.Close();
}

RE: Button_SetCheckState problem by WarPenguin on 03-12-2008 at 06:20 PM

Its working now!!
Thaks a lot!


RE: Button_SetCheckState problem by matty on 03-12-2008 at 06:25 PM

quote:
Originally posted by WarPenguin
Its working now!!
Thaks a lot!
No problem.