Skip to main content
steft66579364
Known Participant
June 28, 2017
Answered

Help with positive and or negative data put into a field

  • June 28, 2017
  • 3 replies
  • 867 views

Hi,

Can someone please help me , I have 10 fields which are populated with measured data.

The data can be positive or negative, but not greater than -10 or +10

If the data being measured is put into any of the fields, is less than or =  -10  / + 10 then I want to populate another field with "pass"

but if the data being put into any of the fields is greater than -10 /+10 then I want to populate the other field with "fail"

This is measured data,microns so can be positive or negative.

Many thanks

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

You would have to copy the script I provided to all eight Pass/Fail fields and then adjust the field name that is checked.

3 replies

Inspiring
June 28, 2017

Do you mean the data needs to be within  +/- 10 of a given measurement or the value needs to be between -10 and +10 .

The following script can handle either case when the correct values for the stand and the range are entered.

// get the data from the form field ;

var d = this.getField("Measurement").valueAsString;  // test field valueAsString;

if(d == "")

{

// no entry for test

event.value = "";

} else {

// report if test result within allowed range;

var nStandard = 15; // required standard;

var nRange = 10; // acceptible variance from standard;

// compute difference from a standard;

var nDiff = Math.abs(nStandard - Number(d))

event.value = (nDiff > nStandard) ? "Fail", : "Pass";

}

One could even write a custom function to indicate a pass or fail for the result when compared to a standard and a range for acceptance.

Such a function could be:

function Results(nStandard, nRange, nTestValue)
{
// function to return logical true or false if test value not within the range for the standard value;
return Math.abs(nStandard - nTestValue) <= nRange;
} // end Results function;

And the custom calculation for the individual result field could then be:


// get the data from the form field ;
var d = this.getField("Measurement").valueAsString;  // test field valueAsString;
if(d == "")
{
// no entry for test
event.value = "";
} else {
// report if test result within allowed range;
var nStandard = 15; // required standard;
var nRange = 10; // acceptible variance from standard;
// compute difference from a standard;
event.value = Results(nStandard, nRange, d) ? "Pass" : "Fail";
}

steft66579364
Known Participant
June 29, 2017

Hello gkaiseril,

really appreciate your response, forgive me if I am wrong but your answer applies to one field

I have 8 fields that all need to be between -10 micron and 10 micron.

How could I write the above the 8 different fields

See below

thank you

Stef

Karl Heinz  Kremer
Community Expert
Community Expert
June 28, 2017

You can use something like the following script as the custom calculation script for your pass/fail field:

// get the data from the form field

var d = this.getField("Data1").value;

if (d == "") {

    event.value = "";

}

else if (Math.abs(d) > 10) {

    event.value = "fail";

}

else if (Math.abs(d) <= 10) {

    event.value = "pass";

}

steft66579364
Known Participant
June 29, 2017

Hello, Karl Heinz Kremer

I tried your script for 8 fields

var h = this.getField("ValueH").value;

var g = this.getField("ValueG").value;

var f = this.getField("ValueF").value;

var e = this.getField("ValueE").value;

var d = this.getField("ValueD").value;

var b = this.getField("ValueB").value;

var a = this.getField("ValueA").value;

if(h==""&&g==""&&f==""&&e==""&&d==""&&c==""&&b==""&&a=="") {

event.value="";

}

else if (Math.abs(h,g,f,e,d,c,b,a) >  10){

event.value "Fail";

}

else if (Math.abs(h,g,f,e,d,c,b,a) < = 10) {

event.value = "Pass";

But I get an error on line 12 ; missing statement

any help please

Stef

Legend
June 29, 2017

You can't replace abs(one thing) with abs(list,of,many,things). You need separate abs for each value. You have to connect them with && (and) or || (or); think about which one is right.

Bernd Alheit
Community Expert
Community Expert
June 28, 2017

steft66579364  wrote

...

The data can be positive or negative, but not greater than -10 or +10

...

Can you explain this? Every positive number is greater than -10.