For Programmers: Free Programming Magazines  


Home > Archive > Clipper > February 2005 > prints and sum contents of an array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author prints and sum contents of an array
happy

2005-02-05, 8:55 am

How can I show the elements of each array created, and accumulate (sum)
the elemtnts of each array.

for i = 1 to d3+2

store "array_"+alltrim(str(i)) to array_na
? array_na
&(array_na):=ARRAY(0)
next


later I use this code :

array_string:="array_"+alltrim(str(arr_no))
aadd(&array_string,2->charge)

Johan Nel

2005-02-05, 8:55 am

Look at my suggestions under your previous question regarding declare and
macro substitution.

--
Johan Nel
Pretoria, South Africa.

"happy" <ehab_aziz2001@yahoo.com> wrote in message
news:1107590954.537357.246840@l41g2000cwc.googlegroups.com...
> How can I show the elements of each array created, and accumulate (sum)
> the elemtnts of each array.
>
> for i = 1 to d3+2
>
> store "array_"+alltrim(str(i)) to array_na
> ? array_na
> &(array_na):=ARRAY(0)
> next
>
>
> later I use this code :
>
> array_string:="array_"+alltrim(str(arr_no))
> aadd(&array_string,2->charge)
>



AUGE_OHR

2005-02-05, 8:55 am

hi

> How can I show the elements of each array created, and accumulate (sum)
> the elemtnts of each array.


perhaps you shoud tell us "what you wanted to do" ?
why you have to create a array, s elements to add instead to sum(found) ?

greetings by OHR
Jimmy


happy

2005-02-05, 3:55 pm

I am adding values of line values let say val1_line,val2_line,val3_line
then I want to gather all val1_line values of all lines to array1 and
val2_line values of all lines to array2.
Just all so I am creating arrays with the columns count which is the
difference between two dates.

Creation phase :
*---------------------
for i = 1 to d3+2
store "array_"+alltrim(str(i)) to array_na
? array_na
&(array_na):=ARRAY(0)
next

In inner loop:
*---------------
....
array_string:="array_"+alltrim(str(arr_no))
aadd(&array_string,2->charge)

.....

happy

2005-02-05, 3:55 pm

Ok I have created the arrays. What is required print the contents of an
array filled with aadd command .

Creation phase :
*---------------------
for i = 1 to d3+2
store "array_"+alltrim(str(i)) to array_na
? array_na
&(array_na):=ARRAY(0)
next

In inner loop:
*---------------
....
array_string:="array_"+alltrim(str(arr_no))
aadd(&array_string,2->charge)

.....

AUGE_OHR

2005-02-05, 8:55 pm

hi,

> I am adding values of line values let say val1_line,val2_line,val3_line
> then I want to gather all val1_line values of all lines to array1 and
> val2_line values of all lines to array2.


your description make no sence to me.

what is "line values" ? is it a data field from your tbrowse cell ?
why do you meen, that you can not SUM(line values) direct ?

> Just all so I am creating arrays with the columns count which is the
> difference between two dates.


dDiff := field->Date2 - field->Date1 is the differnce between two dates, but
what do you want to do with dDiff ? show it in a tbrowse colume ? print it ?

i think you shoud make clear what your Application shoud do, before writing
any line of code.

greetings by OHR
Jimmy


happy

2005-02-06, 3:55 am

I am printing volumes of machines in lines. but every cell of a line
belong to column number I want to have an array1 that gathering all
cells in lines that number1 in their order,...etc array2 will contain
all cells that numbered 2 in the line,...etc

Here main part of my code :


diff:=(V_da_to-V_da_from)
d3:=int(diff/30)

for i = 1 to d3+1
store "array_"+alltrim(str(i)) to array_na
? array_na
&(array_na):=ARRAY(0)
next


for i = 0 to n-1
if i=0
?? space(78)
elseif (i<=11)
?? space(9)
elseif (i>11)
?? space(8)
endif
?? alltrim(str(month(V_da_from+i)))
next


i:=0
?? " Total"
? "-- -------- ------- -------- ---- ---------- --------------------
-------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------"
i:=0
q:=1
select 3
use mach index mach2
go top
select 2
use mete index mete3
go top
tot_colm:=0
tot_line:=0
w:=0
arr_no:=0


do while 3->(!eof())
if (3->mc_start_d)==V_me_START_D
? alltrim(str(q))
if q<10
?? space (2)
else
?? space (1)
endif
set printer off
set console ON
set device to screen
display OFF "Generating file inq0403.prn
Processing Machine # ",alltrim(str(++w)),"record #", 3->(recno())
set console OFF
set device to printer
set printer on
tot_line:=0
arr_no:=0
?? 3->mc_type
?? space (1)
?? 3->mc_serial
?? space (1)
?? 3->mc_cu_ser
?? space (1)
?? 3->mc_model
?? space (1)
?? 3->mc_in_date
?? space (1)
?? 3->mc_brn
?? space (1)
?? (3->mc_me_res)+"_"+(3->mc_me_met)
q++
select 2
go top
do while 2->(!eof())
if
(alltrim(3->mc_serial)==alltrim(2->me_serial)) .AND. ;
(((2->me_date)>=(V_da_from)) .AND.
((2->me_date)<=(V_da_to)))
*?? "month:"
*?? 2->month
*?? " year:"
*?? 2->year
*?? " charge:"
?? 2->charge
tot_line:=tot_line+(2->charge)
skip +1
arr_no++

array_string:="array_"+alltrim(str(arr_no))
aadd(&array_string,2->charge)
? array_string
loop
else
select 2
skip +1
loop
endif
enddo
select 3
skip +1
*?? "total: "
?? tot_line
*tot_line:=0

loop
else

select 3
skip +1
loop
endif

enddo

?
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"

AUGE_OHR

2005-02-06, 8:55 pm

> select 3
> use mach index mach2
> select 2
> use mete index mete3


what is indexkey() mete3 (mc_serial ?)

> ...

you are still on "2" ?

> do while 3->(!eof())
> if (3->mc_start_d)==V_me_START_D
> ?? 3->mc_serial
>....
> select 2
> go top


why you to to Top ?
better SEEK(3->mc_serial) and "SET SCOPE to 3->mc_serial"

> do while 2->(!eof())
> if
> (alltrim(3->mc_serial)==alltrim(2->me_serial)) .AND. ;
> (((2->me_date)>=(V_da_from)) .AND.
> ((2->me_date)<=(V_da_to)))
> ?? 2->charge
> tot_line:=tot_line+(2->charge)


ok, you are doing you SUM 2->charge

> skip +1
> arr_no++
>
> array_string:="array_"+alltrim(str(arr_no))
> aadd(&array_string,2->charge)
> ? array_string


sorry i do not understand why you a doing this ?

you just want to print the SUM from (2->charge) ?
if yes why not " ? STR(tot_line) "

> else
> select 2
> skip +1
> endif
> enddo
> select 3
> skip +1
> *?? "total: "
> ?? tot_line
> *tot_line:=0
> else
> select 3
> skip +1
> endif


greetings by OHR
Jimmy
comment : you are using SKIP +1. if this sample has anything to do with your
"month-opening meter-closing meter-prints" problem, you have to use SKIP
-1 ( beginning from Bottom to Top BOF() )




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com