Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Designer 7 "if" and "esleif" FormCalc

Avatar

Former Community Member
AUGG! I am not a forms designer. This is my very first attempt.



The PDF can be found here:

http://www.fretworksdesign.com/FretDesign%20OrderForm.pdf



Ok, first I want the numbers to show AFTER user input is preformed.



But here is my main issue: The 'Price per Piece' needs to change in relation to the quantity in 'Total Pieces'.



I have it so it changes from $1.15 to $1.05 when the target is reached, but when the next targeted change is reached the 'Price per Piece' stays at $1.05.



This is what I have so far.



----- form1.#subform[0].Body.perPiece::calculate - (FormCalc, client) ------------------------------



if (numTotal <= 125 ) then

perPiece = 1.15



elseif ( 125 > numTotal <= 250 ) then

perPiece = 1.05



elseif ( 250 > numTotal <= 500 ) then

perPiece = 0.95



elseif ( 500 > numTotal <= 1250 ) then

perPiece = 0.85



elseif ( 1250 > numTotal <= 2500 ) then

perPiece = 0.75



endif



HELP ME PLEASE! My pilot mailing is shipping on Tuesday July 8th. And the only order form I have does not work correctly.
3 Replies

Avatar

Level 7
You are trying to create a complex comparison, one using a logical connector. Use 2 simple comparisons and logically connect the results of the 2 simpler comparisons to generate the result of the complex one.



if (numTotal <= 125 ) then

perPiece = 1.15



elseif ( (125 > numTotal) and (numTotal <= 250) ) then

perPiece = 1.05



elseif ( (250 > numTotal) and (numTotal <= 500) ) then

perPiece = 0.95



elseif ( (500 > numTotal) and (numTotal <= 1250) ) then

perPiece = 0.85



elseif ( (1250 > numTotal) and (numTotal <= 2500) ) then

perPiece = 0.75

endif



If you just want to use a simple expression, consider using the "switch()" statement which evaluates an expression compared to a statement to be true and then runs a block of code and skips the other tests.



switch("1") {

case (numTotal <= 125 ) :

perPiece = 1.15

break



case (numTotal <= 250) ) :

perPiece = 1.05

break



case (numTotal <= 500) ) :

perPiece = 0.95

break;



case (numTotal <= 1250) ) :

perPiece = 0.85

break;



defualt:

perPiece = null

break

} // end switch true



elseif ( (1250 > numTotal) and (numTotal <= 2500) ) then

perPiece = 0.75

endif

Avatar

Former Community Member
Close but not yet



The switch statement just gave me errors.



Using the complex comparison the perPiece still shows incorrectly.

The math is showing as:

At 125 Pieces(and lower) = $1.15

At 126-250 Pieces = $0.95

At 251-500 Pieces = $0.85

At 501-1299 Pieces = $0.75

At 1300+ Pieces = $0.00



The math should be:

At 125 Pieces (and lower) = $1.15

At 126-250 Pieces = $1.05

At 251-500 Pieces = $0.95

At 501-1250 Pieces = $0.85

At 1300-2500 Pieces = $0.75

If over 2500 Pieces then CALL US

Avatar

Level 7
Have you double checked the logic of the type comparisons you are using?



Assuming the numTotal value is 126



(numTotal <= 125 ) is the same as



(126 <= 125 ) or false.



((125 > numTotal) and (numTotal <= 250)) is the same as



(125 > 126) and (126 <= 250) or the same as



((false) and (true)) or false.

But you want this result to be true.



((250 > numTotal) and (numTotal <= 500)) is the same as



((250 > 126) and (126 <= 500)) or the same as



((true) and (true)) or true.

And you want this result to be false



It appears you are using the wrong comparison for evaluating the lower limit of the test range.



if (numTotal <= 125 ) then perPiece = 1.15

elseif ( (numTotal > 125) and (numTotal <= 250) ) then perPiece = 1.05



elseif ( (numTotal > 250) and (numTotal <= 500) ) then perPiece = 0.95



elseif ( (numTotal > 500) and (numTotal <= 1250) ) then perPiece = 0.85



elseif ( (numTotal > 1250) and (numTotal <= 2500) ) then perPiece = 0.75



else

$host.messageBox("Requires special pricing, please call us", "Special Pricing Required", 3 , 1 )

perPiece = null

endif