General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
Need help with integer comparison in a conditional expression
Posted by: JamesD
Date: December 20, 2008 02:05AM

I am having a problem getting the answer that I expect when comparing seven to ten in a conditional expression. Seven greater than ten should be false. That is not what I am getting. In addition to that, I get different answers when I run the code in 1.1.6 and 1.5.2 RC2.

My answer is 1 in 1.1.6 but a null value in 1.5.2 RC2,

Any help will be greatly appreciated.

$_Training1_Result = 7;
$_Training1_Result_Bounds = 0:
$_Training1_Result > 10 ? $_Training1_Result_Bounds = 1 :$_Training1_Result_Bounds ="L";
alert($_Training1_Result_Bounds, "bounds >10", "EXCLAIM");


Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: kko
Date: December 20, 2008 01:14PM

Keep in mind that "<", ">", ... do perform string comparisons by default.

7 > 10 is true because the alphabetic order of 7 and 10 is: 10, 7

Try this:

$_Training1_Result_Bounds = +10 < $_Training1_Result ? 1 : "L";

(The first operand determines the type of the operation.)

Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: desga2
Date: December 20, 2008 01:29PM

Note in this line code you are using ":" instead ";":
Quote
JamesD
$_Training1_Result_Bounds = 0:

Instead I think that you like this:
$_Training1_Result_Bounds = 0;

This work fine in 1.5.0 and 1.5.2RC, result is "L".

In 1.1.X the result is "1" because this values ever are considered like strings.
(As kko said in his before post)

In 1.5.X we can indicate to force string value with double quotes without it value is considered integer.

K-Meleon in Spanish



Edited 3 time(s). Last edit at 12/20/2008 01:34PM by desga2.

Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: JamesD
Date: December 20, 2008 08:43PM

Thanks kko and desga2

New macro system for 1.5 versions differs from that for 1.1 versions in that new system can compare integers or strings while the old system can compare only strings. Good information to know.

In writing a new macro, should I care about ability to get same answers on 1.1 versions or only write for 1.5 versions?

Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: desga2
Date: December 20, 2008 09:05PM

Is your macro you do as you want, but if you like write for both version remember this post mine about how to check the K-Meleon version.

K-Meleon in Spanish

Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: kko
Date: December 20, 2008 10:17PM

Quote
JamesD
New macro system for 1.5 versions differs from that for 1.1 versions in that new system can compare integers or strings while the old system can compare only strings.

I haven't said that. There is no difference between 1.1 and 1.5 in this regard.

Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: JamesD
Date: December 21, 2008 01:48AM

@ desga2

Thanks. Seems like every day I learn something new. I will check out the vendor sub. I am sure I will need it in the new project. The macro language changes over versions and now I will be able to adjust for the user's version.

Options: ReplyQuote
Re: Need help with integer comparison in a conditional expression
Posted by: JamesD
Date: December 21, 2008 01:52AM

@ kko

Sorry, I stand corrected.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.