Spellnumber in InfoPath - InfoPath Dev
in

InfoPath Dev

Spellnumber in InfoPath

Last post 09-14-2015 07:20 AM by Hilary Stoupa. 44 replies.
Page 2 of 3 (45 items) < Previous 1 2 3 Next >
Sort Posts: Previous Next
  • 11-20-2008 09:49 AM In reply to

    Re: Spellnumber in InfoPath

     

    Hi guys I was trying to get the cs code to work but I have experiencing errors while debugging it.

     

    Please help

  • 11-20-2008 11:25 AM In reply to

    Re: Spellnumber in InfoPath

    Can you elaborate more on the errors you are getting? Jimmy posted two versions, one for C# in IP 2007 and one for the 2003 OM. Which are you using?

    Hilary Stoupa

  • 11-20-2008 02:17 PM In reply to

    Re: Spellnumber in InfoPath

     Thanks Hilary, I think I have resolved it now, I had to set the Security and Trust option to 'full trust'. However if I uploaded as a browser form to my sharepoint site the code doesn't seem to work please help

    I am using the C# versions.

    Thanks

  • 04-22-2009 04:53 AM In reply to

    Re: Spellnumber in InfoPath

    I tried using the script but get a error: 'null' is null or not an object.   Any ideas?

  • 04-22-2009 07:00 AM In reply to

    Re: Spellnumber in InfoPath

    Never mind; I used this post http://www.infopathdev.com/forums/p/11284/40034.aspx to figure out the xPath was wrong.  Sorry, I am a newbie to Infopath.

  • 06-10-2009 04:20 AM In reply to

    Re: Spellnumber in InfoPath

    Hi Hilary, quick question for you regarding this spell number code.  I've used it previously in a form and it worked like a charm however I'm trying to use it in a new form now so I copied and pasted the code out of the functioning form and into the new form.  I'm now getting an error when I try to open the new form stating that there is a run-time error 'null' is null or not an object.  The error points to line 127 of the code but I can't figure out any issue as it's identical to the code from the previous form!

    Below is the code I'm using, (marked offending line in bold) I would really appreciate some insight into what I'm doing wrong!

    /*
     * This file contains functions for data validation and form-level events.
     * Because the functions are referenced in the form definition (.xsf) file,
     * it is recommended that you do not modify the name of the function,
     * or the name and number of arguments.
     *
    */

    // The following line is created by Microsoft Office InfoPath to define the prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-29T15:17:10" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
    //</namespacesDefinition>

    var c_positions = ["", " thousand", " million", " billion", " trillion", " quadrillion", " quintillion"];
     var c_digits = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
     var c_tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
     var c_teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
       

     function spellNum(num, unitsName, hundredthsName)
        {
            var units = parseInt(num);
            var hundredths = parseInt((num * 100 - parseInt(num) * 100));
            var numberString = spellNumber(units) + " " + unitsName;
            if(units != 1)
            {
                numberString += "s"
            }
            numberString += " and " + spellNumber(hundredths) + " " + hundredthsName;
            if(hundredths != 1)
            {
                numberString += "";
            }
            return numberString;
        }
        function spellNumber(num)
            {
                var negative = false;
                if (num == 0)
                {
                    return "zero";
                }
                if (num < 0)
                {
                    num = -num;
                    negative = true;
                }

                var numString = "";
                var pos = 0;
                while (num > 0)
                {
                    if (num % 1000 != 0)
                    {
                        numString = spellThreeDigits(num % 1000) + c_positions[pos] + numString;
                    }
                    if (parseInt(num / 1000) != 0)
                    {
                        numString = ", " + numString;
                    }
                    num = parseInt(num / 1000);
                    pos++;
                }
                if (negative)
                {
                    numString = "negative " + numString;
                }

                return numString;
            }

        function spellThreeDigits(threeDigits){
            var hundredsDigit = parseInt(threeDigits / 100);
            var tensDigit = parseInt(threeDigits % 100 / 10);
            var onesDigit = threeDigits % 10;
            var numberString = "";
            if (hundredsDigit != 0)
            {
                numberString += c_digits[hundredsDigit] + " hundred";
                if (threeDigits % 100 != 0)
                {
                    numberString += " ";
                }
            }
            return numberString + spellTwoDigits(tensDigit, onesDigit);
        }
        function spellTwoDigits(tensDigit, onesDigit){
            if (tensDigit == 1)
            {
                return c_teens[onesDigit];
            }
            else
            {
                var numberString = c_tens[tensDigit];
               
                if(tensDigit != 0 && onesDigit != 0)
                {
                    numberString += " ";
                }
                numberString += c_digits[onesDigit];
                return numberString;
            }
        }
      
       
    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    // This function is associated with the following field or group (XPath): /my:myFields/my:ChequeAmount
    // Note: Information in this comment is not updated after the function handler is created.
    //=======
    function msoxd_my_ChequeAmount::OnAfterChange(eventObj)
    {
    // Write code here to restore the global state.

     if (eventObj.IsUndoRedo || eventObj.Operation != "Insert")
      {
       // An undo or redo operation has occurred and the DOM is read-only.
       return;
      }

     var amountField = XDocument.DOM.selectSingleNode("/my:myFields/my:ChequeAmount");
     var spelledField = XDocument.DOM.selectSingleNode("/my:myFields/my:AmountWords");
     spelledField.text = spellNum(amountField.text, "Pound", "Pence");
    }

     

  • 06-10-2009 12:01 PM In reply to

    Re: Spellnumber in InfoPath

    Does your new form have the same data structure as your old form? That is, are the XPaths in these lines correct:

     var amountField = XDocument.DOM.selectSingleNode("/my:myFields/my:ChequeAmount");
     var spelledField = XDocument.DOM.selectSingleNode("/my:myFields/my:AmountWords");

    That would be what I'd check first....

    Hilary Stoupa

  • 06-11-2009 01:47 AM In reply to

    Re: Spellnumber in InfoPath

    Yes, those xpaths are correct.  The form does have other different fields than the original form but I have specifically kept these two fields the same....

  • 06-12-2009 09:24 AM In reply to

    Re: Spellnumber in InfoPath

    When you copied and pasted the code, you didn't copy and paste the <namespacesDefinition> at the top, did you? Just the functions?

    Hilary Stoupa

  • 06-12-2009 09:55 AM In reply to

    Re: Spellnumber in InfoPath

    I copied and pasted the entire code from the previous form.  I've also tried just entering the code by programming an "on after change" event on the my:ChequeAmount field and pasting the functions in....that seems to just give me a generic "Cannot Open this Form" error message.  I'm unfortunately pretty crap with code as I've not had any proper training and just go by trial and error but nothing seems to be working this time!

  • 06-14-2009 07:24 PM In reply to

    Re: Spellnumber in InfoPath

     Hiya Ben,

     If you'd be willing to attach your XSN to this thread or e-mail it to Hilary or me, one of us would be happy to look at it for you.  From the above information it's difficult to tell what might be wrong if it's not a misspelling (or mis-capitalization) of the XPath.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-15-2009 09:24 AM In reply to

    Hi Jimmy, tried emailing the form to Hilary but it keeps getting lost somewhere along the way.  Hopefully you or Hilary can help - would really appreciate figuring out where I've gone wrong so I know for the future!

     Here's the form anyway, and the original code I'm trying to use.

  • 06-15-2009 09:50 AM In reply to

    Re: Spellnumber in InfoPath

     Looks like you just attached the JScript.  Will the forum not let you attach XSNs to your posts?  If so, changing the extension to .txt should allow you to do it.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-15-2009 09:52 AM In reply to

    Guess I can only add 1 attachment per post so here's the .xsn file lol

  • 06-15-2009 04:34 PM In reply to

    Re: Spellnumber in InfoPath

     Nice looking form.

     The problem is that when you pasted the JScript code into your new form, you overwrote the auto-generated SelectionNamespaces line, which the JScript uses for locating nodes by their namespaces.  To fix this, open the code and replace this text on line 14:

    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-11-14T18:07:21"

    with this:

    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-21T21:12:27"

    and you should be in the clear.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 2 of 3 (45 items) < Previous 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.