Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: ToText Post Reply Post New Topic
Author Message
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Topic: ToText
    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
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet 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.

Edited by Keikoku - 01 Apr 2011 at 7:07am
IP IP Logged
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Posted: 01 Apr 2011 at 7:16am
So I create the stringvar array in the order that the numbers correspond to the job descriptions?  
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 01 Apr 2011 at 8:25am
Yes, as your indices will rely on that.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.