General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
Question about nested IF statements
Posted by: JamesD
Date: January 22, 2016 08:33PM

I am getting an error about some nested 'if then else' statements. I cannot see any line missing a semicolon. Have I not written the nested if statements correctly? There is nothing but comments prior to the function declaration. I have to get two more languages, but I need the code to work before I do that.

This is the error message. The line number indicates that it the line containing "_AdblockSubs_help {" which throws the error.

Fri Jan 22 2016 15:10:32
Error: ; expected but found {.
Source file: C:\Program Files\K-Meleon76Beta3\Profiles\yftjcc2b.default\macros\adblocksubs.kmm

This is the code.

function KMListBoxLang($__code) {
$_KMListBox_Macro_Path=getfolder(UserMacroFolder)."\\KMListBox" ;
$__CC = "go" ;
if ( $__code == "en" ) { $__fl = "english._en" ; 
   } else { 
   if ( $__code == "de" ) { $__fl = "deutsch._de" ;
   } else {
   if ( $__code == "fr" ) { $__fl = "français._fr" ;
   } else {
   if ( $__code == "es" ) { $__fl = "español._es" ;
   } else {
   alert(_("language provided."), _("No matching"), EXCLAIM) ;
   $__CC = "stop" ;
   }
if ($__CC == "go") {
   $RETURN = copyfile($_KMListBox_Macro_Path."\\language\\".$__fl, $_KMListBox_Macro_Path."\\KMLBlang.dat") ;
   setpref( STRING, "k-meleon_KMListBox_language", $__code) ;
   }   
}

_AdblockSubs_help {
alert("help", "Help", INFO);
}

_AdblockSubs_language {
$__Lcode = substr( getpref( STRING, "intl.accept_languages"), 0 , 2 );
if ( $__Lcode == getpref(STRING, "k-meleon_KMListBox_language") ) {
   alert("match", "Languages");
   } else { KMListBoxLang($__Lcode); }
}


Options: ReplyQuote
Re: Question about nested IF statements
Posted by: siria
Date: January 22, 2016 10:06PM

An editor with syntax highlighting (Scite, Notepad++, etc.) reveals the mystery automatically:

There are lots more opening brackets than closing ones.
Between stop and go must be 4.
(Unless there's more reasons, haven't tested)

This is the same, just easier to read:

function KMListBoxLang($__code) {
$_KMListBox_Macro_Path=getfolder(UserMacroFolder)."\\KMListBox" ;
$__fl="";
$__code == "en" ? $__fl = "english._en" :0;
$__code == "de" ? $__fl = "deutsch._de" :0;
$__code == "fr" ? $__fl = "français._fr" :0;
$__code == "es" ? $__fl = "español._es" :0;
if ($__fl=="") alert(_("language provided."), _("No matching"), EXCLAIM) ;
else {
$RETURN = copyfile($_KMListBox_Macro_Path."\\language\\".$__fl, $_KMListBox_Macro_Path."\\KMLBlang.dat") ;
setpref( STRING, "k-meleon_KMListBox_language", $__code) ;
}
}



Edited 1 time(s). Last edit at 01/22/2016 10:15PM by siria.

Options: ReplyQuote
 
Posted by: adodupan
Date: January 23, 2016 03:02AM

 



Edited 2 time(s). Last edit at 03/21/2016 12:25PM by adodupan.

Options: ReplyQuote
Re: Question about nested IF statements
Posted by: JamesD
Date: January 23, 2016 01:47PM

siria and adodupan

Thanks for the help. I am going to try each method.

I used Notepad++ but with my old eyes, sometimes I just can't see the matching ( ) and { } very well.

The series style by siria is simple to see but I also wish to try the return statement also. I have not seen that before, but should have expected it. I might get tasked to update some documentation.

The whole idea is to have a simple bit of code that a writer of a macro could insert into their code which will match the KMListbox language to the language selected in K-Meleon. The function will not be in their code. The function should be global and exist only once. The call to the function must be just before the use of the listbox. That is because there is no event for a language change.



Edited 1 time(s). Last edit at 01/23/2016 02:00PM by JamesD.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.