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

Creating an Array - Am I Missing Something?

Status
Not open for further replies.

Dond12

Technical User
May 3, 2001
57
US
The answer to this should be obvious, but it's not - at least to me. I am simply trying to create an array. Nothing fancy. I create a formula @CITYSTATE and enter the following:

Whileprintingrecords ;
shared stringvar citystate := [{FILE.CITY},", ",{FILE.STATE}] ;

When I tried to save it, I get the error message:

"The result of a formula cannot be an array."

If this is true, then how do you actually create an array?
 
You create an array just like you said in your formula - (except that you would actually declare the variable as an array by sticking the word 'array' between 'stringvar' and the variable name.

The error message you're getting is trying to tell you that the array is fine if the rest of the formula is going to actually be doing something with the array. The formula can't end on the array - hence, the result of the formula cannot be an array.

However, as you haven't declared this variable as an array, shouldn't what you want be:

Whileprintingrecords ;
shared stringvar citystate := {FILE.CITY}+", "+{FILE.STATE} ;

Naith
 
There is not need for an array or for a variable in this situation, in fact it limits you as you cannot group on this field as it is evaluated WhilePrintingRecords. Just use a formula:


{FILE.CITY}+", "+{FILE.STATE}
Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Yes, thanks. I know your suggestion works; I was only trying to get some practice in creating arrays. The basic stringvar := etc. works. So what you're saying is that my definition of the formula is correct, but that I have to go a bit farther and have the array equal something.
 
Dond12

Crystal doesn't allow an array to be the final result of a formula...just a rule to live with.

Sometimes that is not possible though since all you want to do is initialize one or two arrays....for example:

@Initialize
whilePrintingRecords;
numberVar array test1 := [0,0,0,0,0,0,0];
stringVar array test2 := ["","","","",""];

If I left it like this I would get the error

BUT this is ok since the result is not the array This is the work-around for this situation

@Initialize
whilePrintingRecords;
numberVar array test1 := [0,0,0,0,0,0,0];
stringVar array test2 := ["","","","",""];
"";

Here I have given the formula field a hard-coded null...and now the formula will work fine. Jim Broadbent
 
You can create arrays several ways:

local stringvar array MyArray := Split ({FILE.CITY}+" "+{FILE.STATE})

or

local stringVar array MyArray := [{FILE.CITY},{FILE.STATE}]

or

local stringVar array MyArray := ["Hello", "There"]

or you can create one from a parameter.

local stringVar array MyArray := {?My multiple string parameter}

You can use the Join() function to display the entire array if the total characters are less than 254:

join(MyArray)

Though arrays are powerful, they slow things down, so I avoid them whenever possible.

-k kai@informeddatadecisions.com
 
Thanks, all. This is extremely helpful. I am still learning and every bit of knowledge gets filed away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top