Page 1 of 1

Count on an array

Posted: Wed Apr 29, 2020 4:49 pm
by Silvio.Falconi
i have an arrary and i have to find the totals

Image

of days (column 5)
prices (last column)
of the unitary precious stones column 6

the total of the days and the last column is correct

the total of the unitary column 6 is not fair because I don't want the total of everything

but only by area (column 4) i.e. 01 02 and 03

if he has already taken an area he does not have to take it back again

how can I do ?

the calculation gives me 18 while it should give me back 15

this is the test

Code: Select all

#include "Fivewin.ch"

Function test()
Local cYear:="2020"
Local aData := { ;
                    {"01/07/"+cYear,"31/07/"+cYear,"Alta Stagione","01",31,9,186},;
                    {"01/05/"+cYear,"31/05/"+cYear,"Bassa Stagione","02",0,0,0  },;
                    {"01/09/"+cYear,"20/09/"+cYear,"Bassa Stagione","02",0,0,0  },;
                    {"01/08/"+cYear,"31/08/"+cYear,"Alta Stagione","01",20,9,160},;
                    {"01/06/"+cYear,"30/06/"+cYear,"Bassa Stagione","02",1,6,6  }}

local  nPreTot:=0 ,;
       nPreUni:=0 ,;
       nGiorni:=0
local  n
local nItem:=" "

                   xbrowser aData

                  for n=1 to len(aData)
                     nPreTot+=aData[n][7]
                     nGiorni+=aData[n][5]
                  next

                                n:= 1
                                  do while n < Len( aData )
                                    if aData[n][4]!=nItem
                                       nPreUni+=aData[n][6]
                                       nItem:=aData[n][4]
                                      else
                                      n++
                                   endif
                                enddo



               ? nPreTot,nPreUni,nGiorni
  return nil