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

ToText Experts

Status
Not open for further replies.

bld21

Technical User
Mar 1, 2010
49
US
I am using crystal reports 2008.

I am trying to print an odometer number in a set form field on a page. I am using a formula field with the following syntax. This is working correctly for numbers greater than 9,999. But it does not work for less than 10,000 miles. My if totext() statement seems to not be working.

Example: for 9,964 is prints as 99,64 in the box fields but if the number is 33,167 it will space out correctly.



if {vehicle_title.odometer} = 0 then '' else

if {vehicle_title.odometer} < 10 then

' ' + ' ' + ' ' + ' ' + ' ' + ToText(Truncate({vehicle_title.odometer},0))[1] else

if {vehicle_title.odometer} < 100 then

' ' + ' ' + ' ' + ' ' + ToText(Truncate({vehicle_title.odometer},0))[1] + ToText(Truncate({vehicle_title.odometer},0))[2]

else

if {vehicle_title.odometer} < 1000 then

' ' + ' ' + ' ' + ToText(Truncate({vehicle_title.odometer},0))[1] + ToText(Truncate({vehicle_title.odometer},0))[2] + ToText(Truncate({vehicle_title.odometer},0))[3]

else

if Totext({vehicle_title.odometer})[2] = ',' then

' ' + ' ' + ToText(Truncate({vehicle_title.odometer},0))[1] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[3] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[4] +
' ' + ToText(Truncate({vehicle_title.odometer},0))[5] + ' ' else


if Totext({vehicle_title.odometer})[3] = ',' then

' ' + ToText(Truncate({vehicle_title.odometer},0))[1] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[2] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[4] +
' ' + ToText(Truncate({vehicle_title.odometer},0))[5] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[6]

else

//if Totext({vehicle_title.odometer})[4] = ',' then

ToText(Truncate({vehicle_title.odometer},0))[1] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[2] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[3] +
' ' + ToText(Truncate({vehicle_title.odometer},0))[4] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[5] + ' ' + ToText(Truncate({vehicle_title.odometer},0))[6]



Thanks!!

 

I think you'll find it easier to get rid of the commas before manipulating the text. You could use the replace function and modify the formula you have, but this may be more straightforward - you'll have to tweak the placement and number of the spaces, but you get the idea.

whileprintingrecords;
stringvar v_mileage;
numbervar v_len;

v_mileage := totext({Sheet1_.mileage},"#",0);
v_len := len(v_mileage);

if v_mileage = "0" then ""
else
if v_len = 1 then space(15) + v_mileage
else
if v_len = 2 then space(12) + v_mileage
else
if v_len = 3 then space(9) + v_mileage
else
if v_len = 4 then space(6) + v_mileage[1] + space(3) + v_mileage[2] + space(3) + v_mileage[3] + space(3) + v_mileage[4] + space(3)
else
if v_len = 5 then space(6) + v_mileage[1] + space(3) + v_mileage[2] + space(3) + v_mileage[3] + space(3) + v_mileage[4] + space(3) + v_mileage[5]

 
I copied your code and replaced {vehicle_title.odometer} with another field I had available. After 1000, I started getting some odd things happening. I am trying to understand what you are trying to achieve. I see that you are putting spaces between the numbers from 1000 on. Not sure why you are doing this. Seem like this could be simplified.
 
Crystal will not allow you to build arrays with more than 1000 elements.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top