how to write a formula with an Exponential in infopath 2003 - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

how to write a formula with an Exponential in infopath 2003

Last post 01-23-2010 01:53 PM by spegg. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-20-2010 08:02 PM

    • spegg
    • Not Ranked
    • Joined on 01-19-2010
    • Posts 7

    how to write a formula with an Exponential in infopath 2003

    I did a search on Exponential and did not find an valid answer.  is there any way to multiply a value by an Exponential.

    Or if I try to create a vb script I need a step by step how to add the following function to my form

    I tried to add it to mse and debug but got an error saying something about DOM and debug manager.

    Thank you in advance.

    Steve

     Function MortgagePayment()
    Dim Payments
    Dim Percentage
    Dim Amount

    Amount = XDocument.DOM.selectSingleNode _
    ("/my:myFields/my:PurchPrice").text
    Percentage = XDocument.Dom.SelectSingleNode _
    ("/my:myFields/my:EstRate").text /12
    Payments = XDocument.Dom.SelectSingleNode _
    ("/my:myFields/my:AmortTerms").text

    MortgagePayment = Amount * (Percentage * (1 + Percentage)^Payments)/((1 + Percentage)^Payments-1)
    End Function

     

  • 01-21-2010 12:03 PM In reply to

    Re: how to write a formula with an Exponential in infopath 2003

    Hi Spegg,

    I'm not so familiar VB and scripts so I recreated your scenario using InfoPath 2007 & C#. I did a quick sample form with the following code and it does work. Your formula looks good... I'm just not completely sure if the result I'm getting is correct since I have no sample calculations to compare with.

    Here's the code:

    double Amount;
    double Percentage;
    double Payments;
    double Mortgage;

    XPathNavigator root = MainDataSource.CreateNavigator();
    Amount = double.Parse(root.SelectSingleNode("/my:myFields/my:Amount", NamespaceManager).Value);
    Percentage = double.Parse(root.SelectSingleNode("/my:myFields/my:Percentage", NamespaceManager).Value);
    Payments = double.Parse(root.SelectSingleNode("/my:myFields/my:Payments", NamespaceManager).Value);
    Mortgage = Amount * (Percentage * Math.Pow(1+Percentage, Payments))/(Math.Pow(1+Percentage,Payments-1));
    root.SelectSingleNode("/my:myFields/my:Result", NamespaceManager).SetValue(Mortgage.ToString());

    Hope you find this useful.

    Jett

    using Microsoft.Office.InfoPath;
  • 01-23-2010 08:17 AM In reply to

    • spegg
    • Not Ranked
    • Joined on 01-19-2010
    • Posts 7

    Re: how to write a formula with an Exponential in infopath 2003

    Thank you for your response but I can not use C# in infopath 2003.  When I try to use C#, the tool wants to me to down load visual studio first.  This is a work laptop and I can not download software.  Therefore, the solution must be in 2003.  Again, thank you for your reply and the time you spent.

    Steve

  • 01-23-2010 08:35 AM In reply to

    Re: how to write a formula with an Exponential in infopath 2003

     It would help if you could tell us the actual error message and not something vague like this:

    spegg:
    I tried to add it to mse and debug but got an error saying something about DOM and debug manager.
     

    The problem might be that you're using the wrong capitalization for DOM in these two lines:

     Percentage = XDocument.Dom.SelectSingleNode _

     Percentage = XDocument.Dom.SelectSingleNode _

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-23-2010 01:53 PM In reply to

    • spegg
    • Not Ranked
    • Joined on 01-19-2010
    • Posts 7

    Re: how to write a formula with an Exponential in infopath 2003

    Jimmy, Thanks for replying.

    I created a button and inserted the code below. 

    I tried to clean up my code, but I am a newbie and I am debugging by adding and removing code.  Below is what I currently have and I am currently getting the error "infopath can not open current form" when I try to preview it.  If I remove the As Single. The form will preview but then I get " type mismatch: 'Interest' File: script.vbs line: 29. How do I declare my values as integer, currency and single.  What am I doing wrong.  thanks.

    Sub CTRL64_5_OnClick(eventObj)
    Dim Payment 
    Dim Interest   
    Dim Principle 
    Dim InTerm 
    Dim sgFctr 
    Dim sgInterest As Single
    ' this is line 26
    Principle = XDocument.DOM.selectSingleNode("/my:myFields/my:PurchPrice").text 
    Interest = XDocument.DOM.SelectSingleNode("/my:myFields/my:EstRate").text
    sgInterest = Interest / 12
    InTerm = XDocument.DOM.SelectSingleNode("/my:myFields/my:AmortTerms").text
    sgFctr = (1 + Interest) ^ (InTerm)
    Payment = Interest * sgFctr * Principle / (sgFctr-1)
    PandI.Text = Format(Payment, "Fixed")

    End Sub

     

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.