Print Page | Close Window

ToText

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=12783
Printed Date: 02 May 2024 at 3:19am


Topic: ToText
Posted By: Eldab
Subject: ToText
Date Posted: 01 Apr 2011 at 6:23am
I have a problem where I am trying to convert a numerical value to a text value.  It seems pretty simple but I can't figure this out.

We have a support database that has certain types of jobs.  When I add the job type to the report I just get 0 through 10 as a representation for the job and not the actual name of the job.

So, I'd like to convert the 0 through 10 to represent the actual job type

0 = Field
1= Workshop
2= Onsite

etc. 

Will I need to use IF statements with this also?
I am using CR 10



Replies:
Posted By: Keikoku
Date Posted: 01 Apr 2011 at 7:06am
IF statements is one option, but performance-wise, it would take a hit if you're calling that formula for every record, for thousands of records.

So another option that I prefer is to simply build the list of strings that you want to display and refer to it.

1. Create a formula that will hold an array of strings, where each index corresponds to the job type. You will want to use a global variable and separate this from your formula because re-defining the array also wastes time (though it is minor)


global stringvar array names := ["Field", "Workshop" ... ];
0; //Because you can't return an array, so just return something


Place this formula in the report header because it must be available on the report. Suppress it so it doesn't show.

2. Create another formula that will first declare that you're using the global variable, and then return the element located at that index.


global stringvar array names;
names[{job_type_number}]


Where job type number is a number type field from your description (you can convert it to a number if necessary). Now you don't have to use IF's.


Posted By: Eldab
Date Posted: 01 Apr 2011 at 7:16am
So I create the stringvar array in the order that the numbers correspond to the job descriptions?  


Posted By: Keikoku
Date Posted: 01 Apr 2011 at 8:25am
Yes, as your indices will rely on that.



Print Page | Close Window