Page 1 of 1

Setting array = 0

Posted: May 22 2008
by t123knight
Is there any way I can reset an array to zero without having to do it for every indicitdual cell? For example.

Array: array1[1,1]

if condition1 then begin
array[0,0]=0;
array[1,0]=0;
array[1,0]=0;
array[1,1]=0;
end;

This is fine fo this array because it is small but If I have an array that is 20x20, this is very time consuming. Is there a way I can set the whole thing to zero without having to set them all to zero individually?

Posted: May 23 2008
by Marina Pashkova
Hi t123knight,

Try the sample code below:

--------------------------------

var:
_i(0), _j(0);


For _i = 0 To <Array First Size> Begin
For _j = 0 To <Array Second Size> Begin
arr[_i, _j] = 3;
End;
end;

Posted: May 23 2008
by t123knight
Thanks so much for your help. Ok, this is what I have so far.

Array: SetT[8,3];
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

I'm getting an error that read "equal sign '=' expected" and the cursor stops right at the line "For _i=0 to 8 begin" on the underscore "_" Am I missing something? Also, what does the =3 designate?

Posted: May 24 2008
by drwar
This code is the equivalent to setting each element to zero. It would be good if they provided built in funtions that were optimized, to zero and array or set it to any value. That aside , You did not define condition1 . It may be looking for condition1 "=" to something in the if, then statement.

~J

[quote]Thanks so much for your help. Ok, this is what I have so far.

Array: SetT[8,3];
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

I'm getting an error that read "equal sign '=' expected" and the cursor stops right at the line "For _i=0 to 8 begin" on the underscore "_" Am I missing something? Also, what does the =3 designate?[/quote]

Posted: May 25 2008
by t123knight
Thanks. I actually don't have all the code listed on my example (way too long) so I abreviated that part. Howver, the reast is accurate.

Posted: May 25 2008
by fs
Try replacing the Condition line to something like:

If Condition1 = <something> then begin...

I noticed that PL doesn't always handles it correctly when you set a variable to TRUE/FALSE or 1/0 and you still have to refer to it as "If Condition1 = 1" and just using "if Condition1" doesn't always works.

- Fanus

Posted: May 25 2008
by drwar
fs
I agree, I have seen the same thing occur

J~

Posted: May 26 2008
by Marina Pashkova
Thanks so much for your help. Ok, this is what I have so far.

Array: SetT[8,3];
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

I'm getting an error that read "equal sign '=' expected" and the cursor stops right at the line "For _i=0 to 8 begin" on the underscore "_" Am I missing something? Also, what does the =3 designate?
Hi t123knight,

Array: SetT[8,3](0);
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

Posted: May 26 2008
by Marina Pashkova
Try replacing the Condition line to something like:

If Condition1 = <something> then begin...

I noticed that PL doesn't always handles it correctly when you set a variable to TRUE/FALSE or 1/0 and you still have to refer to it as "If Condition1 = 1" and just using "if Condition1" doesn't always works.

- Fanus
Hi Fanus,

We haven't been able to reproduce the problem you're describing. Could you please contact our customer support representatives at http://messenger.providesupport.com/mes ... pport.html to show them the issue via the remote control connection.

Posted: May 26 2008
by fs
Marina

The following code doesn't compile:
var: Check(0);

If 1 = 1 then Check = 1 else Check = 0;

If Check then buy next bar at open else sell next bar at open;
The following does:
var: Check(0);

If 1 = 1 then Check = 1 else Check = 0;

If Check = 1 then buy next bar at open else sell next bar at open;
and this compiles too..
var: Check(FALSE);

If 1 = 1 then Check = TRUE else Check = FALSE;

If Check then buy next bar at open else sell next bar at open;
I am used to in other programming languages that 0/1 can be substituted for FALSE/TRUE.

Posted: May 27 2008
by Marina Pashkova
This is the way it's supposed to work in EasyLanguage/PowerLanguage

Regards.