Skip to main content
Participant
September 8, 2020
Question

How can I solve the problem "The value entered does not match the format of the field".

  • September 8, 2020
  • 3 replies
  • 709 views

Hello everybody.

 

This is my first time working in Adobe with Java Script.

 

I have created a document in which a certain percentage should be deducted from a value.

 

If all values are subtracted correctly the result should be 0. The formula works fine for some numbers.

With other numbers (for example: 3,6,7,12,14,17,19) the error "The value entered does not match the format of the field" occurs.
 
This is the script I use. Unfortunately I cannot explain the errors at all.

var v1 =

this.getField("Reisetage").value;
var v2 =
this.getField("k-an").value;
var v3 =
this.getField("f-an").value;
var v4 =
this.getField("m-an").value;
var v5 =
this.getField("a-an").value;


var v6 = 0;

if(v1=="ein"){
v6 = 0;
}

if(v1=="mehr"){
v6 = v2 - (v3*20/100*v2)
-(v4*40/100*v2)
-(v5*40/100*v2);
}

this.getField("Anreise").value = v6;

 
Perhaps someone can help me with this problem.
This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
September 8, 2020

This almost always happens when you have a field set as having a Number format and a calculation script that uses division by the value of another field. When that field is empty or zero that results in Infinity (since division by zero is not allowed), which the Number format can't handle. The solution is to add a condition to the code to check that all divisors are not zero before applying the calculation. In your case that would be the value of v2, ie. the "k-an" field.

Bernd Alheit
Community Expert
Community Expert
September 8, 2020

What does you get when you change the format of the field to "None" ?

Marc5FEBAuthor
Participant
September 8, 2020

If you change the format to none, the programme will execute the calculation incorrectly.

I have attached the file.

BarlaeDC
Community Expert
Community Expert
September 8, 2020
Hi, It looks like you have hit one of the quirks of JavaScript and Maths, so when I use the value 3 for all entries, then the Tage field is trying to be set to '8.881784197001252e-16' which is a really small number, and for some reason doesn't get rounded when you apply the formatting to it. If you change your script a little so that the last line is something like: this.getField("Tage").value = util.printf("%.2f", +v7); Then the formatting error is removed. Hope this helps. Malcolm
BarlaeDC
Community Expert
Community Expert
September 8, 2020

HI,

 

Would you be able to share the document that shows the problem, as that would make it easier for us to get to the cause?

 

Regards

 

Malcolm

Marc5FEBAuthor
Participant
September 8, 2020

I have adapted the file.
Maybe there will be some difficulties in understanding the file because it is in German.

The problem arises in the calculations under "Mehrtägige Reise".