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

Split Function Returns Array Error 1

Status
Not open for further replies.

Hillary

Programmer
Feb 15, 2002
377
US
Hi,

I have a report that came with our Student Management Software. This report has a field {Data.Comment}. The field, {Data.Comment} returns comments one on top of another.

Example...

Great progress
A pleasure to have in class
Demonstrates positive attitude

I changed the report so the comments print across - 3 separate fields.

Example...

Great progress A pleasure to have in class Demonstrates positive attitude

I did this using the Split function. I have 3 formulas...

Split ({Data.Comment},chr(13))[1]

Split ({Data.Comment},chr(13))[2]

Split ({Data.Comment},chr(13))[3]

If a student has 0 comments or 3 comments (3 comments is the max # of comments a teacher may enter), the report runs as expected. However, if a teacher enters 1 comment or 2 comments, the system returns the following error...

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

I have tried to evaluate for nulls adding IF(IsNull) to the beginning of the second formula but if there is no second comment it errors.

I think I need to evaluate how many (1, 2 or 3) comments there are before I split, but I'm not sure how to do that.

Does anyone know???

CR 9.0

Thanks,

Hillary
 
Nevermind, I found an old post that had the answer.

I changed the second and third formulas...

//Comment 1
Split ({Data.Comment},chr(13))[1]

//Comment 2
If ubound(split({Data.Comment},chr(13),2)) > 1 then
split({Data.Comment},chr(13))[2]

//Comment 3
If ubound(split({Data.Comment},chr(13),3)) > 2 then
split({Data.Comment},chr(13))[3]



Hillary
 
Check the size of the array in each formula, as in:

if ubound(Split ({Data.Comment},chr(13))) > 0 then
Split ({Data.Comment},chr(13))[1]

if ubound(Split ({Data.Comment},chr(13))) > 1 then
Split ({Data.Comment},chr(13))[2]

if ubound(Split ({Data.Comment},chr(13))) > 2 then
Split ({Data.Comment},chr(13))[3]

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top