Adding values from different rows - InfoPath Dev
in

InfoPath Dev

Adding values from different rows

Last post 04-10-2007 02:12 AM by elektrocad. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 04-04-2007 06:04 AM

    Adding values from different rows

    Hello,

    I want to made a function in a Repeating Table which will ADD a value from the next row's VALUE1 value with next row's VALUE2 value.
    And the function to be a value in the line "before" the next row.
    How can be possibile to do this?

    Ex.:
    1row: VALUE1 VALUE2 SUM
    2row: 5 (2+3)
    3row: 2 3 6 (5+1)
    4row: 5 1


    Thanks,
    Nagy Ferenc
  • 04-04-2007 06:40 AM In reply to

    Re: Adding values from different rows

    Hi elektrocad,

    Its intresting, but your example seems some what confusing, in the 2row there is only one value '5' and in the 3row there are 3 values 2,3,6.


    some understanding point is, in the 2row you are taking the 3row (2,3) value and like that in 3row, 4row (5,1).
    But in between why 6 came, and in 1row what is VALUE1, VALUE2, SUM is it variables?

    can you give another example with extending 2 more rows.
    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
  • 04-04-2007 10:34 PM In reply to

    Re: Adding values from different rows

    Hello,

    OK. The spaces were cuted from the table.
    Here is my example with column separators (|):

    1row: VALUE1 | VALUE2 | SUM (<- the header of the table)
    2row: 0 | 0 | 5 (from the 3row: 2+3)
    3row: 2 | 3 | 6 (from the 4row: 5+1)
    4row: 5 | 1 | 0
    ....

    Thanks,
    Nagy Ferenc
  • 04-05-2007 12:21 AM In reply to

    Re: Adding values from different rows

    Hi elektrocad,

    try this code its working, If possible try to decrese the code. I am writing this code in button click event.

    public void CTRL5_5_OnClick(DocActionEvent e)
    {
    // Write your code here.
    IXMLDOMNode node = thisXDocument.DOM.selectSingleNode("my:myFields/my:group1");
    DOMNodeList xl = thisXDocument.DOM.getElementsByTagName("my:field1");
    DOMNodeList xl1 = thisXDocument.DOM.getElementsByTagName("my:field2");
    DOMNodeList xl2 = thisXDocument.DOM.getElementsByTagName("my:field3");

    ArrayList field1 = new ArrayList();
    ArrayList field2 = new ArrayList();
    ArrayList field3 = new ArrayList();
    foreach(DOMNode x in xl)
    {
    string s = ((System.Object)(((Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper)(x)).nodeTypedValue)).ToString();
    field1.Add(s);
    }
    foreach(DOMNode x in xl1)
    {
    string s = ((System.Object)(((Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper)(x)).nodeTypedValue)).ToString();
    field2.Add(s);
    }
    int index = 1;
    foreach(DOMNode x in xl2)
    {
    ((System.Object)(((Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper)(x)).nodeTypedValue)) = Convert.ToInt16(field1[index]) + Convert.ToInt16(field2[index]);
    index++;
    if(index == xl2.length)
    {
    break;
    }
    }
    }

    try to make your logic simpler.

    Hope this will help you.
    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
  • 04-05-2007 12:26 AM In reply to

    Re: Adding values from different rows

    Hi elektrocad,

    small mistake with the about code if you click the button at the first time by inserting a single row will show the error.

    cut this code

    if(index == xl2.length)
    {
    break;
    }

    and paste before the

    ((System.Object)(((Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper)(x)).nodeTypedValue)) = Convert.ToInt16(field1[index]) + Convert.ToInt16(field2[index]);

    means interchange the statements.

    you will work for the first time also.
    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
  • 04-05-2007 12:39 AM In reply to

    Re: Adding values from different rows

    Thanks.

    I'm using VB.
    If you could translate in VB script it would be greate.
    Firts time I was thinking to resolve this problem with a simple formula inserting in the Value.

    Ex.: in the SUM column I inserted a Value:
    VALUE1[position() + 1] + VALUE2[position() + 1]
    or
    VALUE1[current() + 1] + VALUE2[current() + 1]

    But it's not working.

    Thanks,
    Nagy Ferenc
  • 04-05-2007 01:20 AM In reply to

    Re: Adding values from different rows

    Hi elektrocad,

    I think it is not possible by taking 'position() + 1' in repeated table, you have to write the code by taking the DOM and have do manipulate with your logic. Because InfoPath wont take the value of an individual field in one row to manipulate in another row.

    I will try it in VB Script, you also try to do with the above logic.
    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
  • 04-10-2007 12:20 AM In reply to

    Re: Adding values from different rows

    I resolved this in the source below.
    Just the 3 column headers are not: VALUE1 | VALUE2 | SUM,
    they are: FELUL | NRDOC | BUCIN

    '-------------------------------------
    Sub CTRL43_5_OnClick(eventObj)
    ' Write your code here

    nodeCount = 0
    set nodeList = XDocument.DOM.getElementsByTagName("my:felul")
    for each node in nodeList
    nodeCount = nodeCount + 1
    next
    msgbox nodeCount

    i = 0
    set nodeList = XDocument.DOM.getElementsByTagName("my:bucin")
    for each node in nodeList
    if (nodeCount - 1) = i then exit for
    felul2 = XDocument.DOM.getElementsByTagName("my:felul").Item(i+1).text
    nrdoc2 = XDocument.DOM.getElementsByTagName("my:nrdoc").Item(i+1).text
    bucin1 = felul2 + nrdoc2
    XDocument.DOM.getElementsByTagName("my:bucin").Item(i).text = bucin1

    i = i + 1
    next

    End Sub
    '-------------------------------

    Questions:
    A) Please tell me a function to:
    1. replace my source for nodeCount (to count the nr. of nodes)
    2. for the "bucin1 = felul2 + nrdoc2" line, where the source has to add 2 numbers. My results is always a string.
    Ex.: if in my first 2 columns are 2 numbers: "1" and "1" in the 3rd column (above line) has to be "2" (1+1) and I have always "11" as a string adding. In simply words: to convert string to double.
    B) Using this source in a Repeating Section this source want to resolve my problem in all sections continoulsy. What can I do to transform my source, to made the calculations just for the Section where I press the button. The button is also in the Repeating Section.

    Thanks,
    Nagy Ferenc
  • 04-10-2007 02:12 AM In reply to

    Re: Adding values from different rows

    Hello,

    Regarding to the A)2. problem: I tried to use the number() and val() functions, but just errors.

    Thanks,
    Nagy Ferenc
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.