# Array Problem • ### Question

• Hi all, I apologize for my English, I'm using google translator
I have two arrays, codOV [i] and qnt [i], and if I find identical elements within the array codOV [i] I have to make the sum of the elements in the array qnt [i].
Put simply if both arrays contain the following elements:

I should get the new array in the following form:

I hope that everything is clear and you can help

T.U.

Monday, January 23, 2017 3:05 PM

• And another way: Basicaly step 1 does it all

```For i = 1 To Array.GetItemCount(odOV)
temp[odOV[i]] = temp[odOV[i]]+qnt[i]
EndFor```

And a full program

```'ORIGINAL ARRAYS
qnt = "1=1;2=1;3=1;4=1;5=2;"
TextWindow.WriteLine("odOV : "+odOV)
TextWindow.WriteLine("qnt  : "+qnt)
TextWindow.WriteLine("")

'STEP 1
temp = ""
For i = 1 To Array.GetItemCount(odOV)
temp[odOV[i]] = temp[odOV[i]]+qnt[i]
EndFor
TextWindow.WriteLine("temp : "+temp)

'STEP 2
indices = Array.GetAllIndices(temp)
odOV = ""
qnt = ""
For i = 1 To Array.GetItemCount(temp)
index = indices[i]
odOV[i] = index
qnt[i] = temp[index]
EndFor
TextWindow.WriteLine("odOV : "+odOV)
TextWindow.WriteLine("qnt  : "+qnt)

'OUTPUT RESULT
TextWindow.WriteLine("")
For i = 1 To Array.GetItemCount(odOV)
TextWindow.WriteLine(odOV[i]+" : "+qnt[i])
EndFor
TextWindow.WriteLine("")```

• Marked as answer by Wednesday, January 25, 2017 10:36 AM
Tuesday, January 24, 2017 6:46 PM
• I wrote an algorithm, and it seems to work, I will forward to any future request and also to have it checked to you = P

For i = 1 To Array.GetItemCount(codOV)
If(Array.ContainsValue(cc,codiOV[i])) Then
Goto exit
EndIf
cc[i] = codOV[i]
For j = i+1 To Array.GetItemCount(codOV)
If(codOV[i] = codOV[j]) Then
quantity[i] = quantity[i] + qnt[j]
EndIf
EndFor
quantity[i] = quantity[i] + qnt[i]
exit:
EndFor

For i = 1 To Array.GetItemCount(cc)
GraphicsWindow.ShowMessage(cc[i]+"  "+quantity[i],"")
EndFor

• Marked as answer by Tuesday, January 24, 2017 3:14 PM
Tuesday, January 24, 2017 8:59 AM

### All replies

• What code do you have so far?

Hint:

1] loop though both arrays at the same time, creating a new array indexed by codOV with values set to sum of qnt

2] get the new array indices to back create the new codOV and qnt

Monday, January 23, 2017 6:39 PM
• I wrote an algorithm, and it seems to work, I will forward to any future request and also to have it checked to you = P

For i = 1 To Array.GetItemCount(codOV)
If(Array.ContainsValue(cc,codiOV[i])) Then
Goto exit
EndIf
cc[i] = codOV[i]
For j = i+1 To Array.GetItemCount(codOV)
If(codOV[i] = codOV[j]) Then
quantity[i] = quantity[i] + qnt[j]
EndIf
EndFor
quantity[i] = quantity[i] + qnt[i]
exit:
EndFor

For i = 1 To Array.GetItemCount(cc)
GraphicsWindow.ShowMessage(cc[i]+"  "+quantity[i],"")
EndFor

• Marked as answer by Tuesday, January 24, 2017 3:14 PM
Tuesday, January 24, 2017 8:59 AM
• And another way: Basicaly step 1 does it all

```For i = 1 To Array.GetItemCount(odOV)
temp[odOV[i]] = temp[odOV[i]]+qnt[i]
EndFor```

And a full program

```'ORIGINAL ARRAYS
qnt = "1=1;2=1;3=1;4=1;5=2;"
TextWindow.WriteLine("odOV : "+odOV)
TextWindow.WriteLine("qnt  : "+qnt)
TextWindow.WriteLine("")

'STEP 1
temp = ""
For i = 1 To Array.GetItemCount(odOV)
temp[odOV[i]] = temp[odOV[i]]+qnt[i]
EndFor
TextWindow.WriteLine("temp : "+temp)

'STEP 2
indices = Array.GetAllIndices(temp)
odOV = ""
qnt = ""
For i = 1 To Array.GetItemCount(temp)
index = indices[i]
odOV[i] = index
qnt[i] = temp[index]
EndFor
TextWindow.WriteLine("odOV : "+odOV)
TextWindow.WriteLine("qnt  : "+qnt)

'OUTPUT RESULT
TextWindow.WriteLine("")
For i = 1 To Array.GetItemCount(odOV)
TextWindow.WriteLine(odOV[i]+" : "+qnt[i])
EndFor
TextWindow.WriteLine("")```

• Marked as answer by Wednesday, January 25, 2017 10:36 AM
Tuesday, January 24, 2017 6:46 PM