Answered by:
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:
codOV[i]:{gradone,book,scale,gradone,book}; qnt[i]:{1,1,1,1,2}
I should get the new array in the following form:
codOV[i]:{gradone,book,scale} qnt[i]:{2,3,1}
I hope that everything is clear and you can helpT.U.
Answers

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 odOV = "1=gradone;2=book;3=scale;4=gradone;5=book;" 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 Carmenello Wednesday, January 25, 2017 10:36 AM

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)
For i = 1 To Array.GetItemCount(cc)
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
GraphicsWindow.ShowMessage(cc[i]+" "+quantity[i],"")
EndFor Marked as answer by Carmenello Tuesday, January 24, 2017 3:14 PM
All replies


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)
For i = 1 To Array.GetItemCount(cc)
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
GraphicsWindow.ShowMessage(cc[i]+" "+quantity[i],"")
EndFor Marked as answer by Carmenello Tuesday, January 24, 2017 3:14 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 odOV = "1=gradone;2=book;3=scale;4=gradone;5=book;" 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 Carmenello Wednesday, January 25, 2017 10:36 AM