Putting numeric values into nodes with VB code - InfoPath Dev
in

InfoPath Dev

Putting numeric values into nodes with VB code

Last post 07-19-2006 10:17 AM by Greg Collins. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-28-2006 04:22 PM

    Putting numeric values into nodes with VB code

    I have several text boxes in my InfoPath form that are defined as double precision, as well as other text boxes that are strings (text).

    In VB.net code, I can easily assign the value of a string text box:

    thisXDocument.DOM.selectSingleNode("my:node").text = "Whatever"

    But, what if I want to assign a numeric value to one of the double numeric text boxes? I looked for something like:

    thisXDocument.DOM.selectSingleNode("my:node").Value = 999

    That does not work.

    What does work? I kept on getting an error like:

    '#PCDATA' is in nil content

    If I changed the text boxes to text (string), then everything worked great. But, I did not want them to be string data. I wanted numbers so I could calculate sums, etc.

    After a great deal of search, I found the answer. You have to first remove the "nil attribute". How?

    thisXDocument.DOM.selectSingleNode("my:node").attributes.removeNamedItem("xsi:nil") 'all on one line

    MicroSoft has a KB article (826998) that describes this in jscript.

    http://support.microsoft.com/kb/826998/en-us

    Added later (7/3/2006)

    After some trial and error, I discovered that if I set the decimal defined text boxes to have a default value (zero in my particular case), then I did not have to worry about the PCDATA is in nil content problem at all. I did not have to remove atribute at all. Setting a default value solved the problem for me.

    If you cannot or do not wish to set a default value, or if you are concerned about the user deleting your default, then you need to check to see if there is a nil attribute, then remove it if it is there. That can be done with simple if then end if code.
  • 06-30-2006 10:54 AM In reply to

    Re: Putting numeric values into nodes with VB code

    Keep in mind that all values are stored as text in the XML file... It is the schema that determines the data type of that text value.

    So, when you enter ANY value from code, you do it the same way:

    thisXDocument.DOM.selectSingleNode("my:node").text = "999"

    Hope this helps.
  • 06-30-2006 04:22 PM In reply to

    Re: Putting numeric values into nodes with VB code

    quote:
    Keep in mind that all values are stored as text in the XML file... It is the schema that determines the data type of that text value.
    So, when you enter ANY value from code, you do it the same way:
    thisXDocument.DOM.selectSingleNode("my:node").text = "999"

    Greg, thank you very much for your reply. This subject has been driving me nuts. I set up a simple trial sandbox so I could test code snippets without messing up the main project.

    I have, as I said before, several text boxes defined as doubles. When trying to use the thisXdocument.DOM.selectSingleNode().text statement, I got the PCDATA is in nil content error. I was able to get around that with the method I posted above, in the sandbox.

    BUT BUT BUT

    I took it out of my simple trial sandbox and put it in my main program. Suddenly, the text goes into double defined text boxes without any problem. I don't need the remove named item statement.

    The code is now working just great, getting a number (as you said formatted like "11") into the double defined text box.

    rant WHY DID IT NOT WORK LIKE THAT BEFORE WHEN I FIRST TRIED IT??? /rant

    If you could kindly offer insight on that, I would be in your debt.
  • 07-18-2006 10:02 AM In reply to

    Re: Putting numeric values into nodes with VB code

    Its the mysteries of programming. Why something doesn't work until you try to show someone, or works one time and not another.

    There's probably a valid reason for it, but alas, I have not further insights for you on this.

    I'm glad its working now!
  • 07-18-2006 12:10 PM In reply to

    Re: Putting numeric values into nodes with VB code

    quote:
    There's probably a valid reason for it, but alas, I have not further insights for you on this.

    It has to do with nillable content.

    If I default a value, say "0", in the field, then I can easily fill the field in managed code. If there is no value in the field, then I cannot fill the field in managed code. Or, I remove the nil attribute first, then fill it.

    In this particular problem, assigning 0 as the default value is no problem whatsoever, and the field is read-only to the user. Thus, the problem is solved.

    Thanks for replying!
  • 07-19-2006 10:17 AM In reply to

    Re: Putting numeric values into nodes with VB code

    Thanks for sharing this. Yes - you must ALWAYS remove the xsi:nil attribute before providing a value to a field. If you clear the value of a field, and it is marked as cannot be blank, then you must add back the xsi:nil attribute or else the field will show an error in InfoPath.
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.