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

split function results in null value 2

Status
Not open for further replies.

char473

Technical User
Dec 22, 2006
7
US
Hi All,

I'm using Crystal 10

When the report is run, the following error is received against the formula below;

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

formula:
if ubound(split({tableA.fieldA},"\"[7])) > 0 then
split({tableA.fieldA},"\")[7]
else
""

Here is a few samples of the data

record1 \v1\v2\v3\v4\v5\v6
record2 \v1\v2\v3

record1 reports fine but record2 returns the above message. record2 when evaluated returns a null value. I've tried utilizing isnull, still no good.

Also I've tried the following formula;
//if ubound(split({tableA.fieldA},"\",1)) > 0 then
//split({tableA.fieldA},"\")[1]
//else
//if ubound(split({tableA.fieldA},"\",2)) > 1 then
//split({tableA.fieldA},"\")[2]
//else
//if ubound(split({tableA.fieldA}"\",3)) > 2 then
//split({tableA.fieldA},"\")[3]

** The above I continued to 7
Now this ran but no data for any of the records.

Bottom line is, I want to print the 6th value, if the value does not exist then print ""

WOW, I'm stumped....

Thanks for your help!!!
 
Try something like
Code:
if ubound(split({tableA.fieldA},"\") = 0 
then {tableA.fieldA}
else if ubound(split({tableA.fieldA},"\") = 1
then split({tableA.fieldA},"\")[1]
else ...
I think you went wrong with the number after the split character. But also your options need to check for 1, then 2 then 3 etc. Your test would never cope with occurrences greater than 1 since you test for greater than 1.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Your first formula should have been:

if ubound(split({tableA.fieldA},"\")) >= 7 then
split({tableA.fieldA},"\")[7]
else
""

Ubound gives you the count of the elements in the array, so if you want to show the seventh element if it exists, you need to test the array to ensure that it has 7 or more elements total.

-LB
 
OH MY...You both are brilliant.

I'm utilizing both solutions for different needs.

Thanks so much for being here!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top