Datediff Calculation?

R

Robert Grund

Hello,

I am completely new with Infopath and I am trying to do the following right
now:

In the form I have a starting Date (Format YY.MM.DD HH:MM" and the same as
Ending Date. I need to find out how many hours and minutes have passed
since the beginning and the end.

I understand that I need to make a script with the option OnAfterChange but
I am more oriented torwards the VBA then Jscript.

Just to see if my script works I wanted to write a number into the field

I thought of keying in this

XDocument.DOM.selectSingleNode("/my:CountryGroup/my:Country/my:hours").text
= 2;


but I get always this message

'#PCDATA' is Null-conent

I would like to programm in vbscript and I do not understand further why
Infopath generates the function automatically like this

function msoxd_datum_bis::OnAfterCghange(eventObj)
{
.....
}

I know that this is jscript but I have set in the option vbscript.

Can some one tell me what I have to do so that I can use vbscript in the
backend and also is my current approach correct.

I know many questions but I hope some one can help me out.

Thanks!

Robert
 
S

S.Y.M. Wong-A-Ton

About 6 days ago Sandeep published some VBScript code for date difference
calculations. Do a search on "calculate hours worked from two date/time
cells" in this newsgroup for the code. You may have to modify it to suit your
needs, but it should get you started.

As for the second part of your question: If you opened the Scripting Editor
the first time for your form and you had JScript set as the scripting
language to use in InfoPath, you won't be able to switch to VBScript for that
form anymore by just setting the option through Tools > Options > Design tab
language. Create a new form, set the language to VBScript, and THEN open
the Scripting Editor to be able to use VBScript in your InfoPath form.
 
R

Robert Grund

Thanks!!

That is what I was missing!! I have generated the form while it was still
set to JScript and have opened the Scripting Editor.

That was an information which I was seeking then whole time. The MS Office
Info Publisher 2003 book did not state that.

Robert
 
R

Robert Grund

Still have problems, with Datediff.

The two date fields are currently set as strings and the datediff calculates
the delta nicely. As I need date and time and when I change the field
format to that format, The script crashes!! Also the one field which will
be populated later on shows NaN. Is this normal? Why is it that Datediff
works with string format but not with Date-Time Format? Any suggestions what
I can still do?

I know, I could move to jscript but it will take to long learning a new
language, especially for what I want to do.

Robert
 
S

S.Y.M. Wong-A-Ton

What is the data type of the date fields? Are you using text boxes or date
pickers?
I think you might be confusing the data type with the format (Format button
on the Properties dialog box). Formatting only affects the way a date is
shown.

Did you read my other post where I said that InfoPath date data type has the
format YYYY-MM-DDThh:mm:ss in the background? This might be causing the
problem. Correct me if I'm wrong, but doesn't the DateDiff function accept
Date objects? Perhaps InfoPath's date format cannot be implicitly converted
to a Date object, in which case you will have to parse the date value
returned by InfoPath and explicitly construct a Date object to pass to the
DateDiff function.

NaN is normal if the result of the calculation wasn't a number, which is
true in this case because your calculation failed.

My suggestion would be to add some debugging code to your code. Add MsgBox
statements to print out the values of the date fields. Then use this
information to create valid Date objects in VBScript and pass them to the
DateDiff function. Try it, and if you are experiencing challenges, let me
know; I'll help you where I can.

And there is no need to learn JScript; VBScript should work too!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top