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

splitting data in a field 2

Status
Not open for further replies.

PAULCALLAGHAN

Technical User
Sep 4, 2001
165
CA
Can someone please help me trouble-shoot an error message I keep getting?

I'm using Crystal Reports version 8.5.

The user is entering two pieces of data in a text field, in the format data1/data2. We have no other empty field available to avoid this.

For data1 I have the formula,
StringVar data1:= Split({field},"/")[1];

For data2 I have the formula,
ToNumber(LTrim(Split({field}, "/")[2]));

I want data1 to appear throughout my report but I only want a grand total for data2. Thats why I'm trying to treat it as a number.

Everytime I run the report I get the error message,
"A subscript must be between 1 and the size of the array." This appears when trying to calculate the formula for data2.

What am I doing wrong? Please explain.

 
Most likely, at least one instance of '{field}' doesn't have a '/' in it.

You could try some checking within your data2 formula:
[tt]
if Count(Split({field}, "/")) = 2 and IsNumeric(Split({field}, "/")[2]) then
ToNumber(LTrim(Split({field}, "/")[2]))
else
0;
[/tt]
-dave
 
Thanks vidru. I have checked the data and each occurence of {field} does have a "/" in it.

Any other ideas?
 
Are you getting the same error using the formula I supplied? It should at least help avoid problems such as non-numeric data on the right side of the "/".

-dave
 
This error:

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

States that your trying to use a subscript of the array which does not exist, which implies what Dave suggested, that you do not have a / delimiter in all fields.

Here's a quick sanity check.

Report->Edit Selection Formula->Record

ubound(Split({table.field}, "/")) < 2

If you get any rows, then you have an array less than 2, which states that there isn't a / in the field.

Try modifying Dave's formula:

if instr({field},"/") = 1
and
IsNumeric(Split({field}, "/")[2]) then
val(Split({field}, "/")[2])
else
0;

-k
 
Ooops, that should have been:

if instr({field},"/") > 0
and
IsNumeric(Split({field}, "/")[2]) then
val(Split({field}, "/")[2])
else
0;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top