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

Switch Case (range) problem

PetafromOz
Registered: Jun 8 2009
Posts: 230
Answered

I have several situations where there are 3 or more alternatives that are acceptable.
I have a Hazard factor table that has Min & Max fields, then a user entry field where they enter the Hazard factor (number) they deem to be applicable.

I have a test that enables them to enter either nothing or zero or any number within the given Min/Max range.

In the Exit event, this is what I've done:

var actHaz = this.rawValue;

switch(actHaz)
{
case 0:
xfa.host.setFocus(Haz[1].Hazh);
break;

case (>= HazMin.rawValue) & (<= HazMax.rawValue):
xfa.host.setFocus(Haz[1].Hazh);
break;

case null:
xfa.host.setFocus(Haz[1].Hazh);
break;

default:
xfa.host.messageBox("This 'h' value can only be either 10 or 60. Please re-enter.");
xfa.host.setFocus(this);
break;
}
Everything works except the 'range' case. I assume I've got the syntax wrong. I've been scouring the web but can't find an answer. Does anyone know how I should structure that range test for this?

from way... underground at Parkes - central West NSW - Australia

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
The syntax for the 'switch' statement is:

Quote:
switch (expression){
case label :
statements;
break;
case label :
statements;
break;
...
default : statements;
}

Where:
expression - Value matched against label.

label - Identifier used to match against expression.

statements -Block of statements that is executed once if expression matches label.
If you are going to use a logical expression as the 'label' for the 'case' line you need to place 'true' as the 'expression' value. Then each 'case' 'label' will be compared to the 'true' value and the 'statements' for the 'case' will execute when the logical ANDing or 'expression' & 'label' evaluates to a logical true.
var actHaz = this.rawValue; switch(true) {case (actHaz == 0) :// value is zero // test: 'true' & (actHaz == 0)'xfa.host.setFocus(Haz[1].Hazh);break; case ( (actHaz >= HazMin.rawValue) & (actHaz <= HazMax.rawValue) ):// value is between min and max values// test "true & ( (actHaz >= HazMin.rawValue) & (actHaz <= HazMax.rawValue) )"xfa.host.setFocus(Haz[1].Hazh);break; case (actHaz == null) :// value is null// test "true & (actHaz == Null)"xfa.host.setFocus(Haz[1].Hazh);break; default:// all other conditionsxfa.host.messageBox("This 'h' value can only be either 10 or 60.  Please re-enter.");xfa.host.setFocus(this);break;}

George Kaiser

PetafromOz
Registered: Jun 8 2009
Posts: 230
Hi gkaiseril, I tried it this way as well, and just to be sure, cut & pasted the one you did here - but this doesn't work either. The null and zero tests work fine, but the range test still doesn't. Any value I enter that isn't null or zero is rejected. Maybe I should choose a different event.

from way... underground at Parkes - central West NSW - Australia

PetafromOz
Registered: Jun 8 2009
Posts: 230
I made it work! It may not be the traditional way of thinking, but it works. It didn't seem to matter what I did, 'case' didn't want to do the work of figuring out a range, it seems only to want to act on a 'given'.

So I 'gave' it what it needed by setting another var to the range calculation:

if(this.rawValue >= HazMin.rawValue & this.rawValue <= HazMax.rawValue)
var trueHaz = this.rawValue;

var actHaz = this.rawValue;


switch(actHaz) {
case 0:
break;


case null :
break;


case trueHaz:
break;


default:
// all other conditions
xfa.host.messageBox("This 'h' value can only be either " + HazMin.rawValue + " or " + HazMax.rawValue + ". Please re-enter.");
xfa.host.setFocus(this);
break;
}


Also you'll note that I didn't use the 'true' scenario here. Partly because I now have 2 vars, so I had to distinguish, but also because I tried it both ways before I added that second var and it worked fine either way (except for the range issue, which didn't work either way).

You'll also notice that I removed all the setFocus lines from each except the default, & I changed the message to read the min & max values instead of typing actual values. I did this to make it more generic so I could copy the same script into each of my table lines. There are quite a lot and I didn't want to have to tailor each one.Many thanks for your assistance once again, but as you can see I've come up with another way (whether it's standard or not, I have no idea - but it works).
Peta

from way... underground at Parkes - central West NSW - Australia