Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: can you convert a numeric array to a string array Post Reply Post New Topic
Page  of 3 Next >>
Author Message
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Topic: can you convert a numeric array to a string array
    Posted: 12 May 2011 at 9:06am
I have a numeric array that once was a string array but we were forced to chance it to numeric in order to use it in Record Selector. But pre-existing code for the string array no longer works:
 
if {?Dept_ID} = '' then
    'Corporate' + chr(13) + chr(10) +
    'Education' + chr(13) + chr(10) +
    'Enterprise Architecture Solutions' + chr(13) + chr(10) +
    'Enterprise Program Services' + chr(13) + chr(10) +
    'Enterprise Technology Solutions' + chr(13) + chr(10) +
    'Health & Human Services' + chr(13) + chr(10) +
    'IEP Online' + chr(13) + chr(10) +
    'IT' + chr(13) + chr(10) +
    'LTI' + chr(13) + chr(10) +
    'Pacific North West' + chr(13) + chr(10) +
    'Project Management Solutions' + chr(13) + chr(10) +
    'Public Consulting Group' + chr(13) + chr(10) +
    'Quality Solutions' + chr(13) + chr(10) +
    'Technology Consulting'
else Join ({?Dept_ID}, chr(10) + chr(13))
 
Is there anyway to convert the numeric array ?Dept_ID to a string array so we can use it in the code above?
IP IP Logged
CircleD
Senior Member
Senior Member
Avatar

Joined: 11 Mar 2011
Location: United States
Online Status: Offline
Posts: 251
Quote CircleD Replybullet Posted: 12 May 2011 at 12:36pm
I'm a little weak on formulas but I believe if you open the Format Field for (?Dept_ID) and insert something like totext{field} it should get you close to what you need.If not then someone will be along shortly that knows more than I do.
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 13 May 2011 at 3:25am

Where exactly would i do that?

Where is the format field for parameters?
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 13 May 2011 at 4:11am
You can always create another formula that takes in the numberic array, loops through each value and totext them to string, then add them to a new array.

And then do your record select on it.
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 13 May 2011 at 4:42am
Any code snippets that I can use as an example of your idea?
 
I tried this but I get an error that says "Array must be subscripted"
 
local stringvar array x;
x:=totext({?Dept_ID});
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 13 May 2011 at 6:46am

Global stringvar array x; //new array
Local numbervar j; //counter
Local numbervar num := count ({?Dept_ID}) // length of numbers array

Redim x[num] // resize array to the same size as input array

For j := 1 to num Do
   x[j] := totext({?Dept_ID}[j])


You should be able to reference the string array in your record select formula by declaring x in global scope and then just access it normally.

Edited by Keikoku - 13 May 2011 at 6:47am
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 13 May 2011 at 6:51am
Now what if the array size is dynamic, should I set num = Ubound({?Dept_ID})
 
????
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 13 May 2011 at 8:07am
Sorry I missed: count ({?Dept_ID})
 
 
I'll give it a shot.
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 13 May 2011 at 9:24am
Ok I'm very close to getting it to work: this is the formula (@Dept_Array) that converts the numeric array to a string array:
 
//Variable daclaration section
Global stringvar array x; //new array
Local numbervar j; //counter
Local numbervar num := count ({?Dept_ID}); // length of numbers array
//Loop through the ?Dept_ID array
// resize array to the same size as input array
Redim x[num];
//Loop throug numeric array
//convert each record to text then store in x
For j := 1 to num Do
(
   x[j] := totext({?Dept_ID}[j])
);
 
That works ok, now the new error I get is when I call this formula:
if {@Dept_Array} = '' then
    'Corporate' + chr(13) + chr(10) +
    'Education' + chr(13) + chr(10) +
    'Enterprise Architecture Solutions' + chr(13) + chr(10) +
    'Enterprise Program Services' + chr(13) + chr(10) +
    'Enterprise Technology Solutions' + chr(13) + chr(10) +
    'Health & Human Services' + chr(13) + chr(10) +
    'IEP Online' + chr(13) + chr(10) +
    'IT' + chr(13) + chr(10) +
    'LTI' + chr(13) + chr(10) +
    'Pacific North West' + chr(13) + chr(10) +
    'Project Management Solutions' + chr(13) + chr(10) +
    'Public Consulting Group' + chr(13) + chr(10) +
    'Quality Solutions' + chr(13) + chr(10) +
    'Technology Consulting'
else Join ({@Dept_Array}, chr(10) + chr(13))
 
 
The new error I get is "A boolean is required here" and it points to the ' ' .
 
It's stating that I need a boolean instead of the ' ' (space).
 
 
 
 


Edited by Colonel45 - 13 May 2011 at 9:25am
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 13 May 2011 at 10:02am
Try checking the size of the array.


If count {@Dept_Array} = 0 Then
...


I don't think you can compare an array with a string like that.

UBound seems to do the same thing. I'm not sure what is the difference between the two performance-wise, but it probably doesn't matter too much.

Edited by Keikoku - 13 May 2011 at 10:04am
IP IP Logged
Page  of 3 Next >>
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.015 seconds.