| Author |
declare and macro substitution
|
|
|
| What is wrong with creating those arrays according to difference
between 2 dates .
diff:=(V_da_to-V_da_from)
d3:=int(diff/30)
for i = 1 to d3+1
store "array"+alltrim(str(i))+" [0]" to array
? array
declare array
^^^^^^^^^^^^^
next
| |
| Ron Pinkas 2005-02-04, 3:55 pm |
| > What is wrong with creating those arrays according to difference
> between 2 dates .
>
>
>
> diff:=(V_da_to-V_da_from)
> d3:=int(diff/30)
>
> for i = 1 to d3+1
> store "array"+alltrim(str(i))+" [0]" to array
> ? array
> declare array
> ^^^^^^^^^^^^^
> next
Sorry, but WHERE is the MACRO?
Did you mean to do:
DECLARE &( Array )
?
Ron
| |
| Stephen Quinn 2005-02-05, 3:55 am |
| Ehab
You aren't creating arrrays with that code.
Read the docs - see the ARRAY() function
Why are you using STORE??
Read the docs on STORE and you'll see it's a compatability command and not
recommended for any assignment operation.
Use assignment (:=) instead (less typing).
ie
x := ARRAY(??)
--
HTH
Steve
| |
| hpy_awad@yahoo.com 2005-02-05, 3:55 am |
| > > declare array[color=darkred]
Yes I am sorry . I mean
DECLARE &( Array )
becuase I will later use those created arrays in inner loop
array_string:="array"+alltrim(str(arr_no))
aadd(&array_string,2->charge)
I have error message array doe not exist with the above statement :
declare &(array)
| |
|
| I want to create arrays as needed but also I faced the error array_1
does not exist .
for i = 1 to d3+1
store "array_"+alltrim(str(i)) to array_na
? array_na
array_na:=ARRAY(0)
next
..
..
..
..
array_string:="array_"+alltrim(str(arr_no))
aadd(&array_string,2->charge)
| |
|
| Ok I have done it .
like this :
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)
How then I can show the elmments of each array . and accumulate (sum)
the elemtnts of each array.
Helliouha
| |
| Johan Nel 2005-02-05, 8:55 am |
| I don't think you are writing optimum code here, but here is a solution
doing the same without macro substitution that will be a lot faster.
LOCAL aArray, aArraySum
ASize(aArray, d3+2)
ASize(aArraySum, d3+2)
Afill(aArray, Array(0))
Afill(aArraySum, 0)
Later in your code:
> array_string:="array_"+alltrim(str(arr_no))
> aadd(&array_string,2->charge)
/* I assume you are traversing a database?
There is some redundancy in this code for explanatory purposes.
I would suggest you use aliasnames instead of workarea numbers. */
SELECT 2
2->( GoTop() )
while ! 2->( Eof() )
arr_no := Your calculation of how to determine the element number between
1 and d3 + 2
Aadd(aArray[arr_no], 2->charge)
aArraySum[arr_no] += 2->Charge)
2->( Skip() )
enddo
/* To display items and totals */
for i := 1 to d3+2
for j := 1 to Len(aArray[i])
? i, j, 'Item value:', aArray[i, j]
next
? 'Total of first level array item ', i, aArraySum[i]
next
HTH
--
Johan Nel
Pretoria, South Africa.
"happy" <ehab_aziz2001@yahoo.com> wrote in message
news:1107590063.131186.91420@o13g2000cwo.googlegroups.com...
> Ok I have done it .
> like this :
>
> 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 :
>
>
>
>
> How then I can show the elmments of each array . and accumulate (sum)
> the elemtnts of each array.
> Helliouha
>
|
|
|
|