How to override a calculation with manual entry in results field

Jan 14, 2020

Copy link to clipboard

Copied

I'm designing a form that records a rate of movement by having start and end times entered (in text fields formatted as hh:MM t) and having beginning and ending distances entered (as numbers with two decimal places).

 

For the sake of the example, let:

 

J = Start distance (feet)
K = End distance (feet)
M = Start time (clock time)
P = End time (clock time)
R = Time Interval (in minutes, calculated using Javascript from P & M)
L = Rate of distance over time (inches per minute), calculated with simplified field notation 12*(K-J)/R.

 

My problem is that there are times when the person taking the measurements doesn't keep track of the start and end times, uses a stopwatch and therefore only has the time interval R. So I need them to be able to override the calculation in R with manual input.

 

In plain text, I was trying to do this:

L = 12(K-J) / (P-M)

unless P&M are blank, then

L = 12(K-J) / R

 

Unless there's a way to edit the code in R to allow me to manually override the calculation in that field. This is the code in R:

 

var cStart = this.getField("startTime").value;
var cStop = this.getField("finishTime").value;

if (cStart != "" && cStop != "") {
var tStart = parseTime(cStart);
var tStop = parseTime(cStop);
var total = (tStop - tStart)/(1000*60);
event.value = (total < 0 ? total += 24 : total);
}
else {
event.value = "";
}

 

That code was borrowed and modified from elsewhere, so other than editing the field names to match the input fields in my form, I don't really know what I'm doing with it. There are functions going on here that I don't fully understand, I just know that chunk of code does the calculation I need it to. I just need to be able to override it and allow manual entry of time elapsed in place of start/end time for situations when start and end time is unknown but elapsed time isn't.

remove the else statement completely from the calculation. that is what is blocking you from putting anything in there when the calculation is not running.

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

288

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

How to override a calculation with manual entry in results field

Jan 14, 2020

Copy link to clipboard

Copied

I'm designing a form that records a rate of movement by having start and end times entered (in text fields formatted as hh:MM t) and having beginning and ending distances entered (as numbers with two decimal places).

 

For the sake of the example, let:

 

J = Start distance (feet)
K = End distance (feet)
M = Start time (clock time)
P = End time (clock time)
R = Time Interval (in minutes, calculated using Javascript from P & M)
L = Rate of distance over time (inches per minute), calculated with simplified field notation 12*(K-J)/R.

 

My problem is that there are times when the person taking the measurements doesn't keep track of the start and end times, uses a stopwatch and therefore only has the time interval R. So I need them to be able to override the calculation in R with manual input.

 

In plain text, I was trying to do this:

L = 12(K-J) / (P-M)

unless P&M are blank, then

L = 12(K-J) / R

 

Unless there's a way to edit the code in R to allow me to manually override the calculation in that field. This is the code in R:

 

var cStart = this.getField("startTime").value;
var cStop = this.getField("finishTime").value;

if (cStart != "" && cStop != "") {
var tStart = parseTime(cStart);
var tStop = parseTime(cStop);
var total = (tStop - tStart)/(1000*60);
event.value = (total < 0 ? total += 24 : total);
}
else {
event.value = "";
}

 

That code was borrowed and modified from elsewhere, so other than editing the field names to match the input fields in my form, I don't really know what I'm doing with it. There are functions going on here that I don't fully understand, I just know that chunk of code does the calculation I need it to. I just need to be able to override it and allow manual entry of time elapsed in place of start/end time for situations when start and end time is unknown but elapsed time isn't.

remove the else statement completely from the calculation. that is what is blocking you from putting anything in there when the calculation is not running.

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

289

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
Jan 14, 2020 0
Jan 15, 2020

Copy link to clipboard

Copied

remove the else statement completely from the calculation. that is what is blocking you from putting anything in there when the calculation is not running.

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
Reply
Loading...
Jan 15, 2020 0
Jan 15, 2020

Copy link to clipboard

Copied

That worked! Thanks a bunch. 

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
Reply
Loading...
Jan 15, 2020 0
Jan 15, 2020

Copy link to clipboard

Copied

That's not a good solution, actually. If you do that but then edit the value of any other field in the file the calculated result will overwrite the one you manually entered.

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
Reply
Loading...
Jan 15, 2020 1
Jan 17, 2020

Copy link to clipboard

Copied

So how do I fix that? Any suggestions?

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
Reply
Loading...
Jan 17, 2020 0
Jan 17, 2020

Copy link to clipboard

Copied

MODIFIED REPLY

 

 

++Adding to Try67’s observation, This rate of distance over time formula is expressed incorrectly and therefore the variables are also declared incorrectly.

 

In order to come up with a script that will calculate correctly when  any of the values in the other fields are changed,  this question needs to be rephrased as “How do you find feet per minute with distance and time?

 

In your case you want to apply this formula like this:

 

What is the rate of movement per every minute measured in feet at a constant speed of feet per minute.

 

Since 1 Hour = 60 minutes, and 1 minute = 60 seconds, and 1 foot = 12 inches  We will need to consider how to convert seconds to minutes and minutes to hour.

 

Also, what conditions  does  this script script provides when the feet per distance results in a few feet plus some inches when the clock stopped.

 

If this is not important to consider and you’re ok with rounding a result then disregard

 

But,  what is confusing to me in your equation is that you’re multiplying by 12 which gives you the total in inches, not feet.

 

To get the exact measurement in feet,  shouldn’t it be divided by 12 and then convert the residual inches to feet?  

 

I am under the assumption that that is handled by the formatting of decimal number in your text fields. 

 

So let's say that a user inputs " 5 feet with 12 inches . 

 

Does your script alert the user? 

 

In the format of HH:MM:ss  for example, when  the seconds (:ss)  portion of the end time field is expressed in 59 seconds; No problem.

is input as :60  how is it handled?

 

The same with inches to feet conversion amd vice versa.

 

Would that make any sense?

 

So, the formula rate of movement is   rate = distance / time     OR, in your case rate = feet/minutes. And here is the other confusing part. Where do you get a start distance from ?   How can you input a starting distance if you haven’t started time yet to measure how an object traveled from point A to point B.

 

The way your equation is expressed as of yet,  would only make more sense if you were using some sort of map  grid, and then calculate your travel with a starting coordinate to represent point A and another coordinate to represent Point B.

 

 

Unless you are all of the following  formulas together (1)  rate equals distance divided by time: r = d/t   and be able to  resolve  for (2) distance  (which is rate of movement multiplied by time (d = rt) ) and /  or get the missing starting time  from the end time using (3) distance divided by rate of movement (t = d/r) nothing at this point is helping me understand.

 

 

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
Reply
Loading...
Jan 17, 2020 0
Jan 17, 2020

Copy link to clipboard

Copied

The context is that it's tracking a drilling machine. So "distance" here actually refers to depth in feet. This is a table to record all of these values per drilling interval. My inputs are the starting depth of the interval (J, always 0 in the first entry as a baseline for ground level), finished depth (K, in number of feet below the surface), the time the drilling started (M), and the time the drilling ended (P). I'm calculating the duration of the drilling in minutes (R), because I then have to figure out the rate of drilling speed in inches per minute (L, thus the multiplication by 12, I'm converting from feet to inches). That result is then compared for a boolean check against a variable from a test run and returns either "slower" or "faster" depending on whether the drill rate for that interval was slower or faster than the test run. 

 

It all works as it should and the math checks out. The issue isn't with the math. The only issue I'm having is that I need R to be able to be calculated based on M & P, or to be entered manually by the operator when M & P aren't available because the duration is being timed wth a stopwatch. 

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
Reply
Loading...
Jan 17, 2020 0
Jan 17, 2020

Copy link to clipboard

Copied

At the end of the script you're using you need to add something like  what I posted for you here:

 

https://community.adobe.com/t5/acrobat/override-time-interval-calculation-with-manual-input/m-p/1086... 

 

It seems that you posted the same question in another thread.

 

That't the one I amswered  to before this one.

 

I have not tested this with your script but that is the line of code you need (or similar expression).

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
Reply
Loading...
Jan 17, 2020 0
ls_rbls LATEST
Jan 17, 2020

Copy link to clipboard

Copied

Something like just this line at the end of your script:

 

}

else if ((cStart =="") && (cStop ==""))  {

this.getField("R").value=textObject.value;


}

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
Reply
Loading...
Jan 17, 2020 0