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.
gsuresh17Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GJParkerCommented:
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
0
gsuresh17Author Commented:
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..
0
mlmccCommented:
Where is formula 1 placed in the report?  Formula2?

mlmcc
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

gsuresh17Author Commented:
I have placed formula1 in Group header 1 and suppressed it
0
mlmccCommented:
Formula 2 is in the detail section?

mlmcc
0
gsuresh17Author Commented:
In the same Group Header 1 but not suppressed.
0
mlmccCommented:
Try this.

Open the report
delete formula2 from the group1 header
Reinsert formula2 into the group2 header.

Crystal, in its infinite wisdom, uses order of insertion into the report to determine order of evaluation.  By putting formula2 in last you guarantee the formula1 is evaluated first.

mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gsuresh17Author Commented:
I don't have an Group2 in my report. Anyway I got the logic of evaluation.
0
mlmccCommented:
I meant group 1 (fat fingers strikes again)

Glad i could help

mlmcc
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.