Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Do Structure Query

Status
Not open for further replies.

Flopper

Technical User
Jan 19, 2001
140
AT
Greetings,

The following formula is retrieving the error message:

A subscript must be between 1 and the size of the array.

Formula:
Code:
Global stringvar Array Test;
Local numbervar i:=1;
For i:=1 to 7
Do
    (
    Test[i]:= "Test"+Totext(i);
    i:=i+1;
    );
Test[3];

Why is this happening?!?

Thanks
 
Global stringvar Array Test;
Local numbervar i:=1;
redim test[7];
 
Try this

whileprintingrecords;
Global stringvar Array Test;
Local numbervar i;
redim Test[7];

For i:=1 to ubound(test)
Do
(
Test:= "Test" + totext(i);
);

if ubound(Test) > 2 then
Test[3]


-Steve


"if at first you don't succeed, sky diving is not for you"!!! :eek:)
 
Also if you want to remove the decimal places you can use the following formula

whileprintingrecords;
Global stringvar Array Test;
Local numbervar i;
redim Test[7];

For i:=1 to ubound(test)
Do
(
Test:= "Test" + " " + totext(i,0,"");
);

Test[7]

HTH

-Steve


"if at first you don't succeed, sky diving is not for you"!!! :eek:)
 
Thanks to you both for that...

However why do i have to resize(?) the array considering it's only a local variable?

Cheers
 
You need to resize an array so that Crystal knows how big or how many entries are to be expected in the array. If you don't give the array either a dynamic or fixed size then you will get errors.

The actual array element is not a variable itself as a variable only holds 1 piece of information at a time whereas an array can hold multiple entries at a time.

The local variable part which your refering to is

Local numbervar i;

All that i is doing is basically holding a number, this could be 2, 10, 100 etc.. This number is then used to size the array accordingly to what number i is.

I'll try and dig out some further info for you on array's which might help you.

HTH

-Steve


"if at first you don't succeed, sky diving is not for you"!!! :eek:)
 
Cheers Steve,

Makes a wee bit more sense now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top