Calculating a repeating table column with VB.NET

D

Doug H.

I am using managed code for InfoPath to sum the diff. between two dates and
displaying the "number of days" in the repeating column. The code works fine
on the first row only. If I add a new row the number of days is blank. "the
code fires in debug" but it doesn't use the current selected row node.

How can I sum a column in a repeating row using VB.NET?

Sample LINE:
thisXDocument.DOM.selectSingleNode("/my:myFields/my:Request_Types/my:Request_Type/my:TotalDays").text
= DateDiff("d",
CDate(thisXDocument.DOM.selectSingleNode("/my:myFields/my:Request_Types/my:Request_Type/my:RequestFromDate").text),
CDate(thisXDocument.DOM.selectSingleNode("/my:myFields/my:Request_Types/my:Request_Type/my:RequestToDate").text)) + 1


Thanks,
Doug
 
F

Franck Dauché

Hi Doug,

Where is that code located?

If you have a button on each row to do the calculation, you need to use:
IXMLDOMNode oField1 = e.Source.selectSingleNode("my:RequestFromDate");
IXMLDOMNode oField2 = e.Source.selectSingleNode("my:RequestToDate");

If instead, you are calling that code from the OnAfterChange in one of the 2
dates, use:
IXMLDOMNode oNode = e.Site.selectSingleNode("..");
IXMLDOMNode oField1 = oNode.selectSingleNode("my:RequestFromDate");
IXMLDOMNode oField2 = oNode.selectSingleNode("my:RequestToDate");

Hope that it helps.

Regards,

Franck Dauché
 
D

Doug H.

Franck, Thanks for the response, but I must be doing something wrong.
I added the following code you mentioned and it still updates the first row
only. Yes, this gets fired during the onafterchange event. Should I use an
index number in place of the e.Site.selectSingleNode("..")?

Dim oNode As IXMLDOMNode = e.Site.selectSingleNode("..")
Dim oField1 As IXMLDOMNode =
oNode.selectSingleNode("/my:myFields/my:Request_Types/my:Request_Type/my:RequestFromDate")
Dim oField2 As IXMLDOMNode =
oNode.selectSingleNode("/my:myFields/my:Request_Types/my:Request_Type/my:RequestToDate")

oNode.selectSingleNode("/my:myFields/my:Request_Types/my:Request_Type/my:TotalDays").text = DateDiff("d", CDate(oField1.text), CDate(oField2.text)) + 1

Doug
 
F

Franck Dauché

Hi Doug,

Look at my original post, for oField1, the XPath is: my:RequestFromDate, not
the full: /my:myFields/my:Request_Types/my:Request_Type/my:RequestFromDate
Same for oField2. In fact the full XPath on oNode, should not work at all.

Let me explain: you start from the event, wherever you are in the section.
By selecting "..", you go up one level in your schema to Request_Type. Form
there, you go back to RequestFromDate (the right instance).

Hope that it helps. If my post was useful, don't forget to rate it.

Regards,

Franck Dauché
 
D

Doug H.

Thanks it worked, my mistake.

Doug


Franck Dauché said:
Hi Doug,

Look at my original post, for oField1, the XPath is: my:RequestFromDate, not
the full: /my:myFields/my:Request_Types/my:Request_Type/my:RequestFromDate
Same for oField2. In fact the full XPath on oNode, should not work at all.

Let me explain: you start from the event, wherever you are in the section.
By selecting "..", you go up one level in your schema to Request_Type. Form
there, you go back to RequestFromDate (the right instance).

Hope that it helps. If my post was useful, don't forget to rate it.

Regards,

Franck Dauché
 

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