Count on an array

Count on an array

Postby Silvio.Falconi » Wed Apr 29, 2020 4:49 pm

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  Expand view  RUN
#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








 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 72 guests