Skip to main content
Known Participant
March 15, 2016
Pergunta

nested if statement

  • March 15, 2016
  • 3 respostas
  • 2952 Visualizações

Is there a way to write a custom calculation script to create a nested if statement?  I have been asked to convert an Excel file into a PDF fillable form.

I tried to break it down the best I could.  Please don't laugh at my efforts, I really am a newbie and hope to learn more as I work with these files.

The error I get is SyntaxError: missing ) after condition 3: at line 4.

var v1 = getField("OverdepthRow1").value;

if (v1 !>= 1.3){
var result = v1*1.2;
event.value = result;

if (v1 !>= 1.2){
var result = v1*1.15;
event.value = result;

if (v1 !>= 1.1){
var result = v1*1.1;
event.value = result;

}else(event.value = v1;)

I appreciate any help and advise you can offer.

Thanks!

Este tópico foi fechado para respostas.

3 Respostas

Inspiring
March 15, 2016

You are also missing the closing "}" for each block of code after each if statement. Because of how you have ordered the test, the else might not be necessary since each if will execute in order from the highest value to the lowest value until the if test fails. If you change the order of the test then you need to test the upper and lower values to be tested.

var v1 = getField("OverdepthRow1").value;

event.value = v1;

if (v1 < 1.3) event.value = v1 * 1.2;

if (v1 < 1.2) event.value = v1 * 1.15;

if (v1 < 1.1) event.value = v1 * 1.1;

Inspiring
March 15, 2016

Where you have something like this:

if (v1 !>= 1.3)


Do you mean: "If the variable v1 is not greater than or equal to 1.3"


or something else?

Inspiring
March 15, 2016

Also, if you have a working Excel formula, it would be helpful if you included it here.

Known Participant
March 15, 2016

Here is the excel formula:  =IF(I6>=1.3,G6*1.2,IF(I6>=1.2,G6*1.15,IF(I6>=1.1,G6*1.1,G6)))

Not sure what I was thinking when I added ! (blush)

I forgot to define one of the variables (blush again)

I6 = OverdepthRow1

G6 = WithDowelsRow1

Here's my second stab at it...

var v1 = getField("OverdepthRow1").value;

var v2 = getField("WithDowelsRow1").value;

if (v1 >= 1.3){
var result = v2*1.2;
event.value = result;

else if {v1 !>= 1.2}{
var result = v2*1.15;
event.value = result;

else if {v1 !>= 1.1}{
var result = v2*1.1;
event.value = result;

}else(event.value = v1;)

I don't really understand what you mean about the curley brackets but I did try to put them where I thought you mean.  I haven't got it working yet.

try67
Community Expert
Community Expert
March 15, 2016

Couple of errors:

There's no such operator as "!>=". If you meant to say "not bigger than or equal to" then simply use the "smaller than" operator: "<"

Also, you should put an else before each if statement after the first one. Otherwise all of your conditions except for the last will be useless.

And you need to put curly brackets after the else statement, not parentheses.