Link to home
Start Free TrialLog in
Avatar of gsuresh17
gsuresh17Flag for United States of America

asked on

Invalid Array subscript in Crystal Reports 9

I use Arrays in my formula in CR 9. But when I try to get an value from that array I get an error saying "A subscript must be between 1 and the size of the array". The subscript which I gave is a valid one. Below is the code snippet. Any help appreciated. This is in crystal syntax

Formula 1:

Shared NumberVar Array E := [0,0,0,0] ;
If ( some condition ) then
   E [1] := database field value
Else If ( condition ) then
   E [2] := database field value
--------------
Formula 2:

Shared NumberVar Array E ;
E [2]
--------------
Also I tried to store the Ubound of this array in a numbervar, but I get 0 for that.
Avatar of GJParker
GJParker
Flag of United Kingdom of Great Britain and Northern Ireland image

you don't say which formula is giving you the error  ? formula 1 or formula 2

which section(s) of the report contain the formulas ? formula 2 needs to be evaluated after formula 1 so you will either need to place formula 2 in a section below formula 1 or set the evaluation time of the formulas

amend your formulas  to be

Formula 1:

WhilePrintingRecords;
Shared NumberVar Array E := [0,0,0,0] ;
If ( some condition ) then
   E [1] := database field value
Else If ( condition ) then
   E [2] := database field value
--------------
Formula 2:

EvaluateAfter({@Formula1})
Shared NumberVar Array E ;
E [2]

Gary
Avatar of gsuresh17

ASKER

Formula2 gives the error. I had given the EvaluateAfter function in formula2 earlier. Even though I get that. I missed to give that in this code snippet..
Avatar of Mike McCracken
Mike McCracken

Where is formula 1 placed in the report?  Formula2?

mlmcc
I have placed formula1 in Group header 1 and suppressed it
Formula 2 is in the detail section?

mlmcc
In the same Group Header 1 but not suppressed.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't have an Group2 in my report. Anyway I got the logic of evaluation.
I meant group 1 (fat fingers strikes again)

Glad i could help

mlmcc