Skip to main content
Participant
July 26, 2018
Question

Is it possible to write a calculation formula that isn't based on numbers?

  • July 26, 2018
  • 2 replies
  • 444 views

Is it possible to write a calculation formula that isn't based on numbers?  I am creating a risk assessment worksheet.  There are 2 categories to score-severity and probability.  The available options for severity are I, II, III, IV, and N/A.  The available options for probability are A, B, C, D, and N/A.  Depending on the combination of the 2 options (i.e. I-A, IV-C, etc), the result could be EH, H, M, or L.  Is there a way to calculate the result based on the 2 inputs?  I hope that makes sense.

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
July 26, 2018

You can use a calculation script to do whatever you want (and is possible with JavaScript).  For the problem you've described there are many possible solutions. To find the best one I would suggest writing out a table of results based on the input. This is necessary for writing the basic logic for a solution, but it also provides a visual method of finding a pattern that might simplify the solution. For example, there may be a way to convert the inputs to numbers  that are easier to manipulate, or it may be easier to put the results in an array that is accessed with the inputs.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Loic.Aigon
Legend
July 27, 2018

I don't have a turnkey solution but remembering my middle school technology lessons with electric resistances, a possible approcah woul be to use 2poweredn computations. Eventually, Xn + Yn would be an unique result that would let you know which combination user selected and so display the appropriate value.

Here is a starting point, see if this could help given that you would need to implement it your way :

function doTheMaths() {

    var severity = {

        "I" : 1,

        "II" : 2,

        "III" : 4,

        "IV" : 8,

        "N/A" : 16

    };

   

    var probability = {

        "A" : 32,

        "B" : 64,

        "C" : 128,

        "D" : 256,

        "N/A" : 512

       

    }

   

    var results = {

        1:"EH",

        2:"H",

        3:"M",

        4:"L",

    }

   

console.println("I+A"+ (severity.I+probability.A) );

console.println("I+B"+ (severity.I+probability.B ));

console.println("I+C"+ (severity.I+probability.C) );

console.println ("I+C"+ (severity.I+probability.D) );

console.println ("I+n/A"+ (severity.I+probability["N/A"]) );

console.println ("II+A"+ (severity.II+probability.A) );

console.println ("II+B"+ (severity.II+probability.B) );

console.println ("II+C"+ (severity.II+probability.C) );

console.println ("II+C"+ (severity.II+probability.D) );

console.println ("II+n/A"+ (severity.II+probability["N/A"]) );

console.println ("III+A"+ (severity.III+probability.A) );

console.println ("III+B"+ (severity.III+probability.B) );

console.println ("III+C"+ (severity.III+probability.C) );

console.println ("III+C"+ (severity.III+probability.D) );

console.println ("III+n/A"+ (severity.III+probability["N/A"]) );

console.println ("IV+A"+ (severity.IV+probability.A) );

console.println ("IV+B"+ (severity.IV+probability.B) );

console.println ("IV+C"+ (severity.IV+probability.C) );

console.println ("IV+C"+ (severity.IV+probability.D) );

console.println ("IV+n/A"+ (severity.IV+probability["N/A"]) );

console.println ("N/A+A"+ (severity["N/A"]+probability.A) );

console.println ("N/A+B"+ (severity["N/A"]+probability.B) );

console.println ("N/A+C"+ (severity["N/A"]+probability.C) );

console.println ("N/A+C"+ (severity["N/A"]+probability.D) );

console.println ("N/A+n/A"+ (severity["N/A"]+probability["N/A"]) );

}

doTheMaths();

The idea here is that the sum of Xn and Yn is always unique.

Legend
July 26, 2018

If you can express what you want to do as a set of rules (if this, then that) then you can write it in JavaScript. Numbers are easy to work with but you can compare strings, and set strings as results.