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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array 0 Element Error 1

Status
Not open for further replies.

jenkoller

Programmer
Feb 11, 2005
14
US
I am having a problem handling an array error when I run a report with no data. I use CR XI connecting to a SQL Server database. The report populates an array with medical recommendations for a patient, in the report this data displays on individual lines in the details section, the array is used to display the recommendations in the group footer section for each patient on one line. When there are no recommendations for any of the patients in the report I get the error "An array dimension must be an integer between 1 and 100". The report is grouped by Patient and I have looked in the help sections of CR and read that CR is not able to handle arrays with 0 elements. I am looking for any input on handling this situation so instead of the error they either get a report with blank entries or some type of message displaying "No Records". My codes is below.

@Recommendation //Formula used to populate array
If {USEchoImpressionsAndRecommendations.Impression/Recommendation} = "Recommendation" then {USEchoImpressionsAndRecommendations.Description Detail}

@Recommendation Declare //Placed in group header
WhilePrintingRecords;
Global stringvar Array vRec;
Redim vRec[DistinctCount({@Recommendation})];
Global Numbervar vRecCount := 0;

@Recommendation Populate //Placed in details section
WhilePrintingRecords;
Global Stringvar Array vRec;
Global Numbervar vRecCount;

if not ({@Recommendation} in vRec) then
(
vRecCount := vRecCount + 1;
vRec[vRecCount] := {@Recommendation};
);

@Recommendation Display --Placed in group footer
WhilePrintingRecords;
Global StringVar Array vRec;
replace(replace(Join(vRec, " ** ")," ** **","")," **","")

Thanks in advance for any help you can give.
 
In "@Recommendation Declare" check that there are more than zero recommendations before the redim.
-------------
WhilePrintingRecords;
Global stringvar Array vRec;
if DistinctCount({@Recommendation}) > 0 then
Redim vRec[DistinctCount({@Recommendation})];
-------------

In your other functions check the ubound of the array to determine what to do.
-------------
If ubound(vRec)>0 then
// Carry on as normal
else
// do something to handle the empty array.
 
Simplify a bit:

@Recommendation Declare //Placed in group header
WhilePrintingRecords;
stringvar Array vRec;
Redim vRec;

@Recommendation Populate //Placed in details section
WhilePrintingRecords;
Stringvar Array vRec;
Stringvar CurrRec:="";
If {USEchoImpressionsAndRecommendations.Impression/Recommendation} = "Recommendation" and
not(CurrRec in vRec) then
redim preserve vRec[ubound(vrec)+1];
vRec[ubound(vrec)] := CurrRec;

@Recommendation Display --Placed in group footer
WhilePrintingRecords;
Global StringVar Array vRec;
replace(replace(Join(vRec, " ** ")," ** **","")," **","")

-k
 
Thank you for the quick help. I am having some problems. I am not the best at this so I am not able to figure it out. I am getting the following errors when I try to save the formulas. I have tried the formulas from both posts and am getting errors.

When I try:
@Recommendation Declare
WhilePrintingRecords;
stringvar Array vRec;
Redim vRec; <---I get the error: A [ is expected

@Recommendation Populate
WhilePrintingRecords;
Stringvar Array vRec;
Stringvar CurrRec := "";
If {field} = "Recommendation" and not(CurrRec in vRec) then
redim preserve vRec[ubound(vrec) + 1]; <--Get error: the word 'else' is missing
vRec[ubound(vRec)] := CurrRec;

I have tried to figure out what to put but keep getting errors. Any additional help would be great.

Thanks,

Jen
 
Sorry, going from memory here, but in looking back at this, you don't need an array.

@Recommendation Declare //Placed in group header
WhilePrintingRecords;
stringvar vRec;

@Recommendation Populate //Placed in details section
WhilePrintingRecords;
Stringvar vRec;
Stringvar CurrRec:={USEchoImpressionsAndRecommendations.Description Detail}
;
If {USEchoImpressionsAndRecommendations.Impression/Recommendation} = "Recommendation" and
instr(vRec,CurrRec) = 0 then
vRec := vRec+ "some delimiter" + {USEchoImpressionsAndRecommendations.Description Detail}

@Recommendation Display --Placed in group footer
WhilePrintingRecords;
StringVar vRec

-k
 
Thanks for your help synapsevampire, I still have one issue that is dragging this down. I have placed the 3 formulas in the appropriate areas (group header, details section, and group footer) although the string does not reset itself after each group. What I am seeing is this
Group 1
impression1

Group 2
impression1

Group 3
impression1 + impression3

Can you help me?
 
Sorry, change the group header to:

@Recommendation Declare //Placed in group header
WhilePrintingRecords;
stringvar vRec:="";

-k
 
That did the trick. Thanks so much for teaching me this method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top