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!

A subscript must be between 1 and the length of the string

Status
Not open for further replies.

kelley80209

Programmer
Nov 15, 2002
6
US
Hi All,

I am trying to display numbers as they appear in the database. For example, weight is a single field. If the user puts in 31.1, I want to display 31.1, but the report shows 31.10.

I have used the following formula to display only the decimals that are actually there.....

if isnull({ado.weight}) OR Len(Cstr({ado.weight})) = 0 then
" "
else
StringVar text := Totext ( {ado.weight} , 4, "" ) ;
NumberVar end := length ( text ) ;
NumberVar clip :=

(if Val ( text [ end - 4 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 3 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 2 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 1 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 0 to end ] ) = 0 then 1 else 0 ) ;

text [ 1 to Length ( text ) - clip ] & " kg"


This works fine if there is data in the weight field. If the value is actually null, I get the following error: "A subscript must be between 1 and the length of the string".

Based on this error, it appears that the 'else' statement is being executed. This is not the case. If I replace the code with the following, a blank is displayed.......

if isnull({ado.weight}) OR Len(Cstr({ado.weight})) = 0 then
" "
else
"This is the weight: " & {ado.weight}

Any help would be much appreciated. This is frustrating since it seems CR randomly put 2 decimals on all numeric fields. Grrrrr.

Thanks in advance,
Kelley
 
I thought that formula looked familiar.

Your ELSE doesn't stop it from going to the next step, which is after the next semicolon. So put everything after the ELSE in a single pair of parens (from ELSE to the end). That should prevent it from doing anything after ELSE. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top