none
Array Problems 2 RRS feed

  • Question

  • Hello everyone
    I apologize for my english, I'm using google translator
    I have a problem, I have 3 arrays Object [i] (object), cod [i] (code), qnt [i] (quantity), and I have to sum the quantities of objects that have the same code

    I show you an example:

    Object[i] = {footboard,footboard,step,footboard,step}

    cod[i] = {1,2,1,1,1)

    qnt[i] = {1,2,2,3,1}

    And the final result must be

    Object[i] = {footboard,footboard,step}

    cod[i] = {1,2,1}

    qnt[i] = {4,2,3}

    thank you all for letting me know

    Best

    CL

    Wednesday, January 10, 2018 3:54 PM

Answers

  • Hi,

    Perhaps like this:

    Object = "1=footboard;2=footboard;3=Step;4=footboard;5=Step;"
    cod = "1=1;2=2;3=1;4=1;5=1;"
    qnt = "1=1;2=2;3=2;4=3;5=1;"
    
    Object2 = ""
    cod2 = ""
    qnt2 = ""
    
    For i = 1 To Array.GetItemCount(Object)
      For j = 1 To Array.GetItemCount(Object2)
        If (Object[i] = Object2[j] And cod[i] = cod2[j]) Then
          qnt2[j] = qnt2[j]+qnt[i]
          Goto next
        EndIf
      EndFor
      Object2[j] = Object[i]
      cod2[j] = cod[i]
      qnt2[j] = qnt[i]
      next:
    EndFor
    
    TextWindow.WriteLine(Object2)
    TextWindow.WriteLine(cod2)
    TextWindow.WriteLine(qnt2)

    • Marked as answer by Carmenello Thursday, January 11, 2018 7:19 AM
    • Unmarked as answer by Carmenello Thursday, January 11, 2018 7:19 AM
    • Marked as answer by Carmenello Thursday, January 11, 2018 7:19 AM
    • Edited by litdevModerator Thursday, January 11, 2018 11:33 PM
    Wednesday, January 10, 2018 7:03 PM
    Moderator

All replies

  • Hi,

    Perhaps like this:

    Object = "1=footboard;2=footboard;3=Step;4=footboard;5=Step;"
    cod = "1=1;2=2;3=1;4=1;5=1;"
    qnt = "1=1;2=2;3=2;4=3;5=1;"
    
    Object2 = ""
    cod2 = ""
    qnt2 = ""
    
    For i = 1 To Array.GetItemCount(Object)
      For j = 1 To Array.GetItemCount(Object2)
        If (Object[i] = Object2[j] And cod[i] = cod2[j]) Then
          qnt2[j] = qnt2[j]+qnt[i]
          Goto next
        EndIf
      EndFor
      Object2[j] = Object[i]
      cod2[j] = cod[i]
      qnt2[j] = qnt[i]
      next:
    EndFor
    
    TextWindow.WriteLine(Object2)
    TextWindow.WriteLine(cod2)
    TextWindow.WriteLine(qnt2)

    • Marked as answer by Carmenello Thursday, January 11, 2018 7:19 AM
    • Unmarked as answer by Carmenello Thursday, January 11, 2018 7:19 AM
    • Marked as answer by Carmenello Thursday, January 11, 2018 7:19 AM
    • Edited by litdevModerator Thursday, January 11, 2018 11:33 PM
    Wednesday, January 10, 2018 7:03 PM
    Moderator
  • thank you very much for helping
    Thursday, January 11, 2018 7:19 AM