These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to calculate using text fields to enter accumulated daily minutes of time and sum minutes - to calculate HH:MM i

Kanza71
Registered: Feb 16 2011
Posts: 15

I have built an PDF form by scanning printed document. I then edited PDF and added text field boxes using Adobe Acrobat 9 Pro to keep track of minutes of exercise for seven days per week(a text box to enter minutes on "Monday"...."Sunday"). How do I "sum" daily minutes to then calculate hours and mintues (HH:MM)to be placed in a separate text box called "Weeks Total Exercise". I will need to use AcorForms and Javascript and not Designer. I have tried several ways and have not been sucessful. Please help.

My Product Information:
Acrobat Pro 9.4.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Can you get the minutes to sum to total minutes?

Displaying total minutes as "Hours:Minutes" requires formatting the result as a character string and not a number. The ':" is considered a string character.

Once you get the total minutes, you need to divide by 60 and truncate to get the hours. And then you can use Modulo operation to get the remainder minutes.

A custom calculation script:

// compute the total minutes or get the value from a field
var TotalMin = this.getField("Total").value;
var nHours = TotalMin / 60; // convert to hours
var iHours = parseInt(nHours); // truncate to whole hours
var nMin = TotalMin % 60; // get remainder of division (Modulo)
// define display format
var sFormat = "%,002d"; // display leading zero for hours
sFormat += ":"; // add ":" separator
sFormat += "%,002d"; // display leading zero for minutes
// display formatted result
event.value = util.printf(sFormat, nHours, nMin);


You should not use the date time display formats,as they are for formatting the date and time of an occurrence in time and not the accumulated total of time in a given set of date and time units.

George Kaiser

Kanza71
Registered: Feb 16 2011
Posts: 15
gkaiserll,

Thank you for the custom calculation script. However, I am using format "Time" "Options HH:MM" or format "None" to get HH:MM data to display in textbox "Weeks Total Exercise". However in "Edit layout" when "Weeks Total Exercise" textbox is refreshed with data for example "04:05" an error message appears right before data is displayed/populated in textbox:

"Warning: JavaScript Window - The value entered does not match the format of the field[Text123]"

Please tell me how to elimate this error message? What format should I be using? If I try something other than format "Time" or "None" the calculated daily exercise time does not display. Please help.


gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
How did you get to the value for total minutes?

My script requires a separate field for the displayed value from the field that totals the minutes. If you can write a custom calculation script to to get to the total minutes then you can use one field.

George Kaiser

Kanza71
Registered: Feb 16 2011
Posts: 15
I use separate textbox's - textboxMon, textboxTue, textboxWed, textboxThr, textboxFri, textboxSat, textboxSun to enter daily minutes.

I use a separate field/textbox "Text18A" to sum minutes:
- under Text Field Properties I select "Calculate" "Value is the sum(+) of the following fields:" I pick "textboxMon, textboxTue ..... textboxSun".
- under Text Field Properties I select "Format" None

I then use another/separate field/textbox "Text18B" - in Text Field Properties - under Calculate I selected Custom calculation script and placed the following script -> "var TotalMin = this.getField("Text18A").value;", including all the script listed above. (I also use Format - Select format category: None)// compute the total minutes or get the value from a field
var TotalMin = this.getField("Text18A").value;
var nHours = TotalMin / 60; // convert to hours
var iHours = parseInt(nHours); // truncate to whole hours
var nMin = TotalMin % 60; // get remainder of division (Modulo)
// define display format
var sFormat = "%,002d"; // display leading zero for hours
sFormat += ":"; // add ":" separator
sFormat += "%,002d"; // display leading zero for minutes
// display formatted result
event.value = util.printf(sFormat, nHours, nMin);


The script works except: first the javascript error pops up - I then click "OK" button and the correct HH:MM data appears in textbox18B.

I hope this helps you to help me. There is probably something that I am not doing or doing wrong? Please help.

Kanza71
Registered: Feb 16 2011
Posts: 15
Below is the script that I am using - however, still getting error - please help me remove error.
"Warning: JavaScript Window - The value entered does not match the format of the field[Text123] (OK)

Script is totaling correct Weeks' total minutes and displaying:
// display formatted result
event.value = util.printf(sFormat, nHours, nMin);

var v1 = 1*this.getField("Text5").value;
var v2 = 1*this.getField("Text7").value;
var v3 = 1*this.getField("Text9").value;
var v4 = 1*this.getField("Text11").value;
var v5 = 1*this.getField("Text13").value;
var v6 = 1*this.getField("Text15").value;
var v7 = 1*this.getField("Text17").value;
var vtot = (v1 + v2 + v3 + v4 + v5 + v6 + v7);

// compute the total minutes or get the value from a field
var nHours = vtot / 60; // convert to hours
var iHours = parseInt(nHours); // truncate to whole hours
var nMin = vtot % 60; // get remainder of division (Modulo)
// define display format
var sFormat = "%,002d"; // display leading zero for hours
sFormat += ":"; // add ":" separator
sFormat += "%,002d"; // display leading zero for minutes
// display formatted result
event.value = util.printf(sFormat, nHours, nMin);

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Set the field's format to None, since you're already taking care of it in your script.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Kanza71
Registered: Feb 16 2011
Posts: 15
I have set all my textbox text fields properties to "Format None" and still geting pop-up javascript error.

I am new to javascript - I just do not know why the error is occurring? - Please help.
Kanza71
Registered: Feb 16 2011
Posts: 15
I have set all my textbox text fields properties to "Format None" and still geting pop-up javascript error.

I am new to javascript - I just do not know why the error is occurring? - Please help.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Form fields do not always work independently of other fields. You may have a different field causing the problem.

Have you looked at the JavaScirpt debugging console for errors?
Have you looked at the other calculations on the form?
Have you tried to disable all the calculations and reinstate them one at a time from the lowest levels to the highest levels?

A smaple fo the form might be helpful.

George Kaiser

Kanza71
Registered: Feb 16 2011
Posts: 15
George, how do I forward a samples of the form to you. Do you have an address? I am really new at this.
Kanza71
Registered: Feb 16 2011
Posts: 15
I forwarded copy of my PDF form - for your review "team [at] acrobatusers [dot] com"
Kanza71
Registered: Feb 16 2011
Posts: 15
Hello,

I am having a problem, with two items:

First of all, the script that sums seven textbox variables and takes sum to calculate weeks Hours and Minutes of exercise is not rounding minutes correctly. For example, if time should be 3:30(three hours and thirty minutes) the PDF form script displays time of 3:20). Do I have an error in this line of code? see line of code below:

var nMin = vtot % 60; // get remainder of division (Modulo)

Secondly, I am trying to set up a counter when a textbox actully contains a text type of exercise I want to add 1 to a counter-of-daily-exercise and then in a separate text box "Week's total days" I want to display counter-of-daily-exerise. I am not having any success. See the code below:

//Daily textbox of exercise
M1 = this.getField("Text6").value;
if (M1!=null){
var dateCount = dateCount + 1;
}else{
var dateCount = dateCount + 0;}

//Weekly total days textbox
event.value = dateCount;
var dateCount = 0;
var M1 = 0;
var D2 = 0;
var W1 = 0;
var H1 = 0;
var F1 = 0;
var A1 = 0;
var U1 = 0;

I have forwarded an example copy of my PDF form. PLEASE - I'D APPRECIATE YOUR HELP. Thanks in advance.

Kanza71



try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't do something like this:
var dateCount = dateCount + 1;

What value are you incrementing here? You are just declaring this variable.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I do not have access to that email address.

Have you been able to total the minutes for a week?

How do you record your daily work out time?
In Minutes?
In Hours:Minutes?

Realize the the time format for Acrobat JS is the specific point in time from the Epoch date. This is not the same as a time interval, as it includes date as well as time information, and the time values allowed must be between 00:00 and 323:59.999, or the time interval can not exceed 24 hours.

Now if you are going to add time intervals. the format of the elapsed time is important. If it is just minutes for each day, one can easily add the minutes to obtain the total minutes. But if it hours and minutes, then one needs to convert the hours and minutes to the equivalent in minutes only before summing the minutes.

George Kaiser

Kanza71
Registered: Feb 16 2011
Posts: 15
try67,

In a PDF - I have seven textbox's in a row/line for each day of the week to enter an activity code like "W" for walking. When an alpha code is entered into each textbox I want to add 1 to a "dateCount" counter for each code filled textbox. I want use the sum of "dateCount" counter and place the value in the eighth textbox in the row/line. So, If an activity/exercise code is entered for seven days a week at the end of the week my eighth/separate textbox "dateCount" value should be "7". Also, if there is no activity on a day of the week textbox would be filled with (spaces or nulls) and "dateCount" counter would not be incremented by 1 and at end of week "dateCount" textbox value should be "6". Do I need a declare a global variable and increment it too, or this even possible? I'd appreciate your help.

Kanza71

try67
Expert
Registered: Oct 30 2008
Posts: 2398
I'm not really following what you want to do, but I don't think you need a global variable for it. A simple calculation script that loops over all of these fields and increments a variable if they are filled-in should suffice.

My comment was more regarding your coding style.
When you use the "var" keyword you are defining a variable. It's impossible to declare a variable and use its value in the same line, by the simple fact that that variable doesn't exist yet.
If you run this code in the console:
var a = a + 1;
app.alert(a);
you will see that the value of a afterwards is NaN (Not a Number).

You can either declare a variable, like so:
var a = 12;
or change an already existing variable's value, like so:
a = a + 1;
But not both in the same line.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Kanza71
Registered: Feb 16 2011
Posts: 15
George,

How may I forward my pdf form?

I appreciate your comments from 2011-02-21 16:30:12. With your help I now have the weekly sum of minutes into HH:MM and seven weeks of minutes into HH:MM.

However, I still need some help doing the following:

On same the PDF form - I have seven textbox's in a row/line for each day of the week to enter an activity code like "W" for walking. When an alpha code is entered into each textbox I want to add 1 to a "dateCount" counter for each code filled textbox. I want use the sum of "dateCount" counter and place the value in the eighth textbox in the row/line. So, If an activity/exercise code is entered for seven days a week at the end of week one my eighth/separate textbox "dateCount" value should be "7". Also, if there is no activity on a day of the week the textbox would be filled with (spaces or nulls) and "dateCount" counter would (not be) incremented by 1 and at end of week one "dateCount" textbox value should be "6". Do I need a declare a global variable and increment it too, or this even possible?

Also, I need to sum up the seven weeks of "total days of exercise". For example, during each week I had three codes of "W" - meaning three days of exercise for seven weeks at the end of seven weeks I would have exercised 3 X 7 = "21 days of total exercise". Do I need a global variable to tally total days of exercise.

I'd appreciate your help. Thanks.

Kanza71




Kanza71
Registered: Feb 16 2011
Posts: 15
try67,

Could you give me an example of a simple calculation script that loops over all of these text fields and increments a variable if they are filled-in?

Kanza71
RobJE
Registered: Nov 7 2008
Posts: 1
Hi gkaiseril
I used the script you originally posted here, and it works very well. However, I have separated out the minutes and hours fields into att_mins and att_hrs - what would I need to add to your script to get the hours element from the att_mins calculation to add to my att_hrs total?

// compute the total minutes or get the value from a field
var TotalMin = this.getField("att_mins27").value + this.getField("att_mins28").value + this.getField("att_mins29").value;
var nHours = TotalMin / 60; // convert to hours
var iHours = parseInt(nHours); // truncate to whole hours
var nMin = TotalMin % 60; // get remainder of division (Modulo)
// define display format
var sFormat = "%,002d"; // display leading zero for hours
sFormat += ":"; // add ":" separator
sFormat += "%,002d"; // display leading zero for minutes
// display formatted result
event.value = util.printf(sFormat, nHours, nMin);

Your help much appreciated