Yet another Date Picker Calculation

L

Larry Cook

I have two date pickers and a text field. One of the Date Pickers is a
Target Date and the second is the Actual Competion Date. I want a positive
or negative result in days in the third field. How do I subtract two date
pickers? I have tried the examples here and have not been able to get it to
work. I have little programming knowledge. Thanks in advance, Larry
 
L

Larry Cook

Yes the "Calculating date and time differences with custom VBScript code" was
very helpful and I got the example to work on my practice form, but when I
entered a end date before a start date I got a zero number. I need to have a
negative number. I want to track projects. A target date and a completion
date. If a person gets a project done ahead of time they have a positive
number in days. If they are behind schedule I want it to be a negative
number.

The second example "Calculating date differences in InfoPath using VBScript
code" was confusing to me. I was unsure on where to put the code. You
listed a Function code section and then the code for the ISODateToVBDate
function. It was unclear to me on how to insert the code into my form.

Thanks for you time,

Larry
 
S

S.Y.M. Wong-A-Ton

All solutions posted on the website are examples on how you could get
something done in InfoPath. Needless to say, you need to modify them to suit
your own needs. I can impossibly cater for every InfoPath scenario that there
might be out there. :)

In "Calculating date and time differences with custom VBScript code" you
need to modify the calcTimeInMinutes function to use in your own situation.
And since you are only dealing with dates, you need to strip out the times.
Change the last line of the function to

calcTimeInMinutes = intDateDiffMin

and remove everything between and including

If intDateDiffMin >= 0 Then
....
End If

and you should be good to go.

The second example "Calculating date differences in InfoPath using VBScript
code" states somewhere in the text just after the ISODateToVBDate function to
"Add the following code to the event handler of a field or button". So you
either need to add a button and put the code in its event handler or add an
OnAfterChange event handler for one of the fields on your form. The
ISODateToVBDate function can go anywhere in the form's code as long as it's
not placed inside another function or event handler.
 
Top