Print Page | Close Window

Tonumber not working

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=19154
Printed Date: 20 Apr 2025 at 10:38am


Topic: Tonumber not working
Posted By: lyman
Subject: Tonumber not working
Date Posted: 20 Feb 2013 at 8:03am
I'm trying to sort blood pressure readings (120/90)  in order so I parse out the first number and sort them. My formula(s) are  
If NumericText({text_1}) then
TONumber(Left({text_1},InStr(1,1},"/")-1)) else
0
 
The error message is "String length is less than 0 or not an integer"
 
If InStr({text_1},"/")>1 then
ToNumber(Left({text_1},InStr(1,{text_1},"/")-1)) else
0
 
Error message: The string is non-numeric.
 
What am I doing wrong here. 
 
 



Replies:
Posted By: hilfy
Date Posted: 20 Feb 2013 at 11:12am
Is there any chance that {text_1} is null?  If so, you need to do one or more of the following things:
 
1.  In the Formula Editor, look for "Exceptions for nulls" in the button bars at the top of the screen.  Change it to "Default values for nulls".
 
2.  Go to the File menu and select Report Options and turn on "Convert NULL values to default".
 
3.  Handle it the old-fashioned way by checking for null in your formula - something like this:
 
If IsNull({text_1}) or not NumericText({text_1}) then 0
else ToNumber(Left({text_1},InStr(1,1},"/")-1))
 
NOTE:  If using method 3 you ALWAYS have to test for NULL first!
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window