calculations in infopath using VB - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

calculations in infopath using VB

Last post 08-20-2010 06:08 AM by sanvir. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 08-16-2010 01:04 AM

    • sanvir
    • Top 500 Contributor
      Male
    • Joined on 03-03-2010
    • South Africa
    • Posts 30

    calculations in infopath using VB

    HI,

    I am trying to do calculations in infopath, but i cannot seem to get them working.

    I have little experience in infopath so im not sure what i am doing wrong. this is what i currently have:

    Dim rate1 As Integer
    Dim Randamt1 As Integer
    Dim foramt1 As Integer
            
    Rate1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Rate1", NamespaceManager).Value
    Randamt1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt1", NamespaceManager).Value
    foramt1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Foramt1", NamespaceManager).Value

    Randamt1 = Rate1 * foramt1

  • 08-16-2010 05:34 AM In reply to

    Re: calculations in infopath using VB

    You need to set the new value in your "Randamt1" field.

     MainDataSource.CreateNavigator().SelectSingleNode("my:myFields/my:Ramdamt1", NamespaceManager).SetValue(Randamt1);

  • 08-16-2010 07:28 AM In reply to

    • sanvir
    • Top 500 Contributor
      Male
    • Joined on 03-03-2010
    • South Africa
    • Posts 30

    Re: calculations in infopath using VB

     Hi mgarant,

    Thank you very much!! it works!

    would i do the same for adding up values?

    I would also like to know what to do if there is not value in the fields as i am going to have 3 different exchange rates and converting them into the Rand value.

    i Presume i would need an If statement, but im not sure how to go about doing this.

    Thanks for the help again! 

  • 08-16-2010 08:00 AM In reply to

    • sanvir
    • Top 500 Contributor
      Male
    • Joined on 03-03-2010
    • South Africa
    • Posts 30

    Re: calculations in infopath using VB

     I have tried this code for the other fields, but im getting this error: "Schema validation found non-data type errors."

    I dont get the error on Randamt1, but get this error on the ones after..

                Dim rate1 As String
                Dim rate2 As String
                Dim rate3 As String
                Dim Randamt1 As String
                Dim Randamt2 As String
                Dim Randamt3 As String
                Dim Randamt4 As String
                Dim Randamt5 As String
                Dim foramt1 As String
                Dim foramt2 As String
                Dim foramt3 As String
                Dim foramt4 As String
                Dim foramt5 As String



                rate1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Rate1", NamespaceManager).Value
                rate2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Rate2", NamespaceManager).Value
                rate3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Rate3", NamespaceManager).Value
                foramt1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Foramt1", NamespaceManager).Value
                foramt2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Foramt2", NamespaceManager).Value
                foramt3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Foramt3", NamespaceManager).Value
                foramt4 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Foramt4", NamespaceManager).Value
                foramt5 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Foramt5", NamespaceManager).Value
                Randamt1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt1", NamespaceManager).Value
                Randamt2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt2", NamespaceManager).Value
                Randamt3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt3", NamespaceManager).Value
                Randamt4 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt4", NamespaceManager).Value
                Randamt5 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt5", NamespaceManager).Value

                Randamt1 = rate1 * foramt1
                MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt1", NamespaceManager).SetValue(Randamt1)

                Randamt2 = rate1 * foramt2
                MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt2", NamespaceManager).SetValue(Randamt2)

                Randamt3 = rate1 * foramt3
                MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt3", NamespaceManager).SetValue(Randamt3)

                Randamt4 = rate1 * foramt4
                MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt4", NamespaceManager).SetValue(Randamt4)

                Randamt5 = rate1 * foramt5
                MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Randamt5", NamespaceManager).SetValue(Randamt5)
     

     

     

  • 08-16-2010 09:29 AM In reply to

    Re: calculations in infopath using VB

    Are your fieds of text type? I think this may be the issue... They need to be of text type if you want to write in them with code.

  • 08-16-2010 05:36 PM In reply to

    Re: calculations in infopath using VB

    Generally you see this error when you try to set the value of a field that is not text without first removing the nil attribute. Please see this blog post for more info...

    Hilary Stoupa

  • 08-20-2010 02:03 AM In reply to

    • sanvir
    • Top 500 Contributor
      Male
    • Joined on 03-03-2010
    • South Africa
    • Posts 30

    Re: calculations in infopath using VB

     thank you for the help again!

    I have changed the field types to text (they were set to integer).

    I have 1 last problem! how do i add up the fields numbers?

    i have tried: Totrandamt1 = randamt1 + randamt2 + randamt3.   but this just shows the numbers in the fields and does not add them up.

  • 08-20-2010 04:46 AM In reply to

    • sanvir
    • Top 500 Contributor
      Male
    • Joined on 03-03-2010
    • South Africa
    • Posts 30

    Re: calculations in infopath using VB

     ok, i got it working..

    i used totrandamt1 = CInt(rantamt1) + CInt(randamt2) etc..

     How do i get the total field to show the full amount and not just a round figure (eg: 3.45 instead of 3)

  • 08-20-2010 04:55 AM In reply to

    Re: calculations in infopath using VB

    You are using integer values so u r getting result also as an int. Try to parse values into double and then add them up.

    Vishal Srivastava
    Senior Software Engineer
    SDG Software Pvt Ltd
  • 08-20-2010 06:08 AM In reply to

    • sanvir
    • Top 500 Contributor
      Male
    • Joined on 03-03-2010
    • South Africa
    • Posts 30

    Re: calculations in infopath using VB

     thanks for the help!

     

    i got it working finally!! 

    instead of using CInt, i used CDbl and i worked with the decimal values!

     

    thanks again

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