Help with Formula

New Here ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

Help please.

I have a sheet where I want to calculate all the fields from 1 to 22 but not include the ones that have the zeros (=N/A).  then also have the zeros (n/a) = 4 to be deducted by total points of 88

do that number would be the dividend

 

Scores in the field range from 1 to 4 and 0 or N/A if they did not meet that criteria.

 

I also want to get the grade of the criterias were scored on

 

TOPICS
How to , JavaScript , PDF forms

Views

103

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

I don't think we have enough information to create a script for you, but it also sounds like the script would be a bit too complex for something that could be posted as part of a reply here.

 

Have you tried to create the script yourself? If so, what do you have currently? Based on the information we have, it sounds like you need to create a JavaScript. If you are new to JavaScript, it can be a daunting task to get started. I did write up some information about how to get started with scripting for Acrobat: http://khkonsulting.com/2017/01/learning-to-program-javascript-for-adobe-acrobat/

 

If this still sounds a bit too complex, you may want to reach out to somebody who can write such a script for you (and no, I am not currently taking on any new projects). 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Hi Karl

Let me explain a little

I have fields SS0 to SS21 with dropdown to select 0, 1, 2, 3, 4

This is what I want

There are 22 criteria and each criterion can have a maximum point of 4 points, therefore, 22 X 4 = 88
Maximum points may vary depending on the total number of criteria addressed during the evaluation. If criteria is not evaluated, enter “N/A” and these will be deducted from the maximum points.
To compute the student’s grade:
Total points received (excluding N/A) / Maximum points possible 88 X 100 = % grade
Example: Student received 80 points (had 2 N/A) / 88 X 100 = 90.9%

This is what I currently have. I keep getting zero. Your help is appreciated.

var nCount = 0;

var nSum = 0;

var na = 0;

event.value = 0;

for( var i=1; i<=6; i++){

if(this.getField("SS0"+i).valueAsString == "N/A"){

na++;

if(na == 6)

event.value = "N/A";}

else if(this.getField("SS0"+i).valueAsString != "N/A" && this.getField("SS0"+i).valueAsString != "" && this.getField("SS0"+i).valueAsString != 0){

nCount++;

nSum += Number(this.getField("SS0"+i).value);

event.value = nSum/nCount;}}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Sorry the selection in dropdow is 1,2,3,4 and N/A

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

If your fields start with 0 then set i to 0: i=0; and remove 0 from field name like this: this.getField("SS"+i).

EDIT: If you have 6 fields then also set i<=5, and you can remove condition where you check if field's value is not  0 or "" since it's a dropdown field and all values you have are 1,2,3,4,N/A.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Ms. Nesa, 

 

I am still getting an error. 

 

CCamacho_0-1661798535333.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

var nCount = 0;
var nSum = 0;
var na = 0;
event.value = 0;
for( var i=1; i<=6; i++){
if(this.getField("SS0"+i).valueAsString == "N/A"){
na++;
if(na == 6)
event.value = "N/A";}
var nCount = 0;
var nSum = 0;
var na = 0;
event.value = 0;
for( var i=0; i<=21; i++){
if(this.getField("SS"+i).valueAsString == "N/A"){
na++;
if(na == 21)
event.value = "N/A";}
else if(this.getField("SS"+i).valueAsString != "N/A" && this.getField("SS"+i).valueAsString != "" && this.getField("SS"+i).valueAsString != 0){
nCount++;
nSum += Number(this.getField("SS"+i).value);
event.value = nSum/nCount;}}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Why are you using two scripts? Which one do you want with 6 fields or 21?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

The one with 21...since I have 22 criteria for students to meet. Sorry about the confusion, I was testing it. 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Try this:

var nCount = 0;
var nSum = 0;
var na = 0;
event.value = 0;
for( var i=0; i<=21; i++){
if(this.getField("SS"+i).valueAsString == "N/A"){
na++;
if(na == 21)
event.value = "N/A";}
else if(this.getField("SS"+i).valueAsString != "N/A"){
nCount++;
nSum += Number(this.getField("SS"+i).value);
event.value = nSum/nCount;}}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Ms. Nesa, do my fields have to be formatted as numbers? 

I still get zero for the answer. It shows no errors. 

I am so sorry for all the questions. I am learning JavaScript.

I WILL GET THIS! WITH YOUR HELP 🙂 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

There is a good chance that a ")" is missing from your code - somewhere. Just as the error message indicates. The "{" and "}" always need to show up in pairs, and need to match. A good way to aviod this problem is to use an editor that "speaks" JavaScript and allows you to reformat your code so that it is indented. This way, you can spot a missing } without a problem. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Hi Experts, 

I don't think I am accomplishing what I want on this form. 

Your responses are appreciated. 

What am I missing?

CCamacho_0-1661799987472.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

You set it to calculate average. So the calculation should be nSum/88*100?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Ms. Nesa,

I still do not get the calculation. There are no errors.  What should I be looking at?

 

var nCount = 0;
var nSum = 0;
var na = 0;
event.value = 0;
for( var i=0; i<=21; i++){
if(this.getField("SS"+i).valueAsString == "N/A"){
na++;
if(na == 21)
event.value = "N/A";}
else if(this.getField("SS"+i).valueAsString != "N/A"){
nCount++;
nSum += Number(this.getField("SS"+i).value);
event.value = nSum/nCount;}
(nSum/88*100)}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Replace nSum/nCount with nSum/88*100 if that's the calculation you want.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

LATEST

Can I email you the form so that you can see it? I need so much help.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

The line

 (nSum/88*100)

makes no sense.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

Here is a general debugging tip: If you don't know why a certain condition is not met, it's a good idea to print out the values of the variables that are involved. Add a console.println("this variable = " + thisVariable); [of course, adjusted to your specific needs] in appropriate places in your code to see what's going on. 

 

As Bernd said, the last line does not make any sense: You are calculating something, but then not doing anything with the result of that calculation. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines