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
<< Prev Page  of 3 Next >>
Author Message
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 16 May 2011 at 2:58am
I get an error message that says "An array is required here" for the {@Dept_Array} value
 
if ubound ({@Dept_Array}) = 1 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 only way I can the IF porting of the statement to work is if I do the following: if ubound ({?Dept_ID}) = 1 then
 
But then the section under the ELSE give me an arrary stating that an array is required here.
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 16 May 2011 at 3:05am
That's strange.
It seems that you get the number of elements in the IF clause, so it clearly is an array.

I am not sure what the problem might be given the above condition.
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 16 May 2011 at 3:12am
if ubound ({?Dept_ID}) = 1 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))
 
 
Actually to be exact it says a STRING array is required here in the ELSE section. So if I use ?Dept_ID or ?Dept_Array from your code below it still is looking for a STRING array. Code for the ?Dept_Array formula field is below:
 
//Variable daclaration section
Global stringvar array x; //new array
Local numbervar j; //counter
Local numbervar num := count ({?Dept_ID}); // length of numbers array
//resize array to the same size as input array
Redim x[num];
//Loop through numeric array
//convert each record to text then store in x
For j := 1 to num Do
(
   x[j] := totext({?Dept_ID}[j])
);
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 16 May 2011 at 3:35am
I declared it as a string array so in the other formula where you're actually printing it out, you would first have to declare it as a string array as well before it will let you proceed.
IP IP Logged
Colonel45
Newbie
Newbie


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

Shouldn't i just be able to reference the ?Dept_Array in the formula that I'm using to print out the contents of the array?

Do you mean somethingl like this:
 
Global stringvar array x;
x = {@Dept_Array};
 
I tried that earlier and it didn't work.
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 16 May 2011 at 6:23am
So there's no straight forward way to convert a numeric array to a string array?
 
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 16 May 2011 at 9:59am
Seems like I overlooked something somewhat important:

x is the new string array that we created.


Global stringvar array x;
if ubound (x) = 1 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 (x, chr(10) + chr(13))
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 18 May 2011 at 3:58am
Your code worked, not fully but worked. I had to combine everything into on formula:
 
Global stringvar array x;
Local numbervar j; //counter
Local numbervar num := count ({?Dept_ID});  
 
Redim x[num];
 
For j := 1 to num Do
(
   x[j] := totext({?Dept_ID}[j])
);
 
if ubound (x) = 1 
and
   x[1] = '0.00'
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 Test' //+ ' If section -- ' + x[1]
else Join (x, chr(10) + chr(13))
 
I had to account for my default value which is the number 0 which once you convert it to string turns into '0.00'.
 
So it does convert all the dept_ID values into string but the format is the following:
 
#,###,###.##
 
So dept ID 5000008 gets turned into 5,000,008.00
 
Which is not a huge deal but now I need to figure out a way to convert that string dept_id into a the real name, look at the picture I posted in the earlier portion of the thread that shows my DEPT_ID input parm with the values and the description. I need to some how take 5,000,008.00 and display the word Corporate and so on and so on for all the values in the array.
 
How do I look though this new array and based on the value build a string that list all the real department names?
 
Value                                  Description
5000006                             Education
5000008                             Corporate
5000012                             IT
 
 
ect....
 
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 18 May 2011 at 4:07am
Out of curiosity: did you place my stringArray-conversion formula into the report header?

Otherwise, crystal won't run it and so the array won't exist when you try to access it later on. I would put it in the RH because anything else that requires this data to be available most likely comes after it.

Regarding the names, you probably didn't even need the array. You can just use a number of if/else if statements, to accomplish it.

if string = 50000008 then
   ...
else if string = 500000012 then
   ...
else if ...

...

I'm not sure what the array is for actually.

Edited by Keikoku - 18 May 2011 at 4:13am
IP IP Logged
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 18 May 2011 at 4:12am

So I would need to get the upper bound of the array then stick an if/elseif in there?

Can you show a short example of using an array with an if/elseif?
 
Also I found an easier way to convert a numeric array to string:
Global Numbervar i;
Global Stringvar DisplayString;
For i := 1 to ubound({?Dept_ID})
Do
DisplayString := DisplayString + cstr({?Dept_ID},0,"") + Chrw(13) ;
DisplayString
 
 
IP IP Logged
<< Prev 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.031 seconds.