These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How can I compare a range of numbers?

StevenD
Registered: Oct 6 2006
Posts: 368

In others words if the value of a numeric field is between 94 and 109 then I want to do something. Can someone tell me how to do this? Please.

StevenD

My Product Information:
LiveCycle Designer, Windows
StevenD
Registered: Oct 6 2006
Posts: 368
Never mind I think I got it.

var myVal = NumericField1.rawValue;
if (myVal >= 94 && myVal <= 109)
{
Do something.
}

I didn't think I was going to find it that quick.

StevenD

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
One can use a compound comaprison using the logical "&" operator:var Range = Number(this.getField("MyField").value);
if (Range > 94 & Range < 109) {
// do something
app.alert("The value is between 94 and 109", 4, 0);
}Or you could even use the "switch" statement

var Range = Number(this.getField("MyField").value);
switch(true) {
case (Range <= 94) :
// do nothing
break;case (Range >= 109) :
// do nothing
break;// use compound test statment for the case
case (Range > 94 & Range < 109) :
// or use the default case
default:
app.alert("You are within the range between 94 and 109", 4, 0);
break;
}

George Kaiser

StevenD
Registered: Oct 6 2006
Posts: 368
Shouldn't I be using "&&" instead of "&"?I was hoping to use a switch statement but have been able to get anything to work using a compound statement like you suggest.

I am doing this in LiveCycle Designer.

StevenD

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
& Bitwise AND a & b Returns a one in each bit position for which the corresponding bits of both operands are ones.&& expr1 && expr2 (Logical AND) Returns expr1 if it can be
converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.Examples The following code shows examples of the && (logical AND) operator.a1=true && true // t && t returns truea2=true && false // t && f returns falsea3=false && true // f && t returns falsea4=false && (3 == 4) // f && f returns falsea5="Cat" && "Dog" // t && t returns Doga6=false && "Cat" // f && t returns falsea7="Cat" && false // t && f returns falseIt would appear either should work. You might have to use parenthesis to order the comparisons. But I use the single "&".

George Kaiser

StevenD
Registered: Oct 6 2006
Posts: 368
Here is what I tried to use in my LiveCycle Designer document.

var myVal = NumericField8.rawValue;

switch (myVal)
{
case (myVal >= 94 & myVal <= 109) : RadioButtonList.rawValue = "5"; break;
case 110 : RadioButtonList.rawValue = "6"; break;
default : RadioButtonList.rawValue = "0"; break;
}It is supposed to set the 5th radio button in a group of radio buttons as checked if the value is between 94 and 109. I couldn't get this to work. But I did get the following to work.

//Get the value of NumericField8.
var myVal = NumericField8.rawValue;

if(myVal >= 94 && myVal <= 109)
{
RadioButtonList.rawValue="5"; //Turn on radio button 5.
}
else
if(myVal == 110)
{
RadioButtonList.rawValue="6"; //Turn on radio button 6.
}
else
{
RadioButtonList.rawValue="0"; //Don't turn any radio buttons on.
}

StevenD