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
Author Message
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 18 May 2011 at 4:19am
That seems like a normal string to me, although I guess you could split on chrw(13) to get string array.

To go through each string number and convert it to a different string, one could say


for x := 1 to ubound(array)
   if array[x] = "00001" then
      "some string"
   else if array[x] = "00002" then
      "some other string"


But it is quite inefficient. There may be other ways to do it.

Edited by Keikoku - 18 May 2011 at 4:20am
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 5:05am
This is what I ended up having to do:
 
stringVar array a := {@Dept_Array};
numbervar b:=0;
Global Stringvar DeptString;
for b:=1 to ubound(a)
do
if left(a,7) = "5000001"
    then DeptString:= DeptString + 'Public Consulting Group' + chrw(13)
else if left(a,7) = "5000002"
    then DeptString:= DeptString + 'Health And Human Services' + chrw(13)
else if left(a,7) = "5000006"
    then DeptString:= DeptString + 'Education' + chrw(13)
else if left(a,7) = "5000008"
    then DeptString:= DeptString + 'Corporate' + chrw(13)
else if left(a,7) = "5000012"
    then DeptString:= DeptString + 'IT' + chrw(13)
else if left(a,7) = "5000741"
    then DeptString:= DeptString + 'CRM' + chrw(13)
else if left(a,7) = "5000961"
    then DeptString:= DeptString + 'Technology Consulting' + chrw(13)
else
    DeptString := 'Else section - TEST TEST ' + join(a);
DeptString
 
 
 
The only problem is if a user selects multiple department's then it only selects one, it won't build the string correctly. If you select three departments I'd want it to display all three. Is there an alternative to if/then?
 
If you select three department's I'd like to display
 
Dept1
Dept2
Dept3
 
 


Edited by Colonel45 - 18 May 2011 at 5:07am
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 5:19am
It should not be an issue because you take an array of string numbers and loop over each item.

The purpose of looping it is to build your string with all of the items and eventually end up with the desired list of departments.

I am not sure why it would be only displaying one.

Verify that the number of items in the array matches the number of options selected.
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 5:49am
Should there be a loop statement at the bottom?
 
The ubound(a) is returning a value of 1. I also tried a count(a) and it also returns the value of 1.
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 6:08am
This is the code for @Dept_Array:
 
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
Colonel45
Newbie
Newbie


Joined: 10 May 2011
Location: United States
Online Status: Offline
Posts: 35
Quote Colonel45 Replybullet Posted: 18 May 2011 at 6:24am
Could it be that I'm not passing an array instead it's receiving a string value (@Dept_Array)?
 
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 8:32am
Anyone out there that can figure out why this code is not working????
 
local stringVar array a := {@Dept_Array};
local numbervar b:=1;
Global Stringvar DeptString;
for b:=1 to ubound(a)
do
if left(a,7) = "5000001"
    then DeptString:= DeptString + 'Public Consulting Group' + chrw(13)
else if left(a,7) = "5000002"
    then DeptString:= DeptString + 'Health And Human Services' + chrw(13)
else if left(a,7) = "5000006"
    then DeptString:= DeptString + 'Education' + chrw(13)
else if left(a,7) = "5000008"
    then DeptString:= DeptString + 'Corporate '  + chrw(13)
else if left(a,7) = "5000012"
    then DeptString:= DeptString + 'IT' + chrw(13)
else if left(a,7) = "5000741"
    then DeptString:= DeptString + 'CRM' + chrw(13)
else if left(a,7) = "5000961"
    then DeptString:= DeptString + 'Technology Consulting' + chrw(13)
else
    DeptString :=    'Corporate' + cstr(ubound(a)) + 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';
DeptString
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 10:06am
Originally posted by Colonel45

Could it be that I'm not passing an array instead it's receiving a string value (@Dept_Array)?
 


Your formula is creating a string.

Global Stringvar DisplayString;


You will also have to modify your loop, once you pass in the an array. Or create an array somehow, like for example splitting on chrw(13).

local stringVar array a := {@Dept_Array};
local numbervar b:=1;
Global Stringvar DeptString;
for x:=1 to ubound(a)
do
if left(a[x],7) = "5000001"
    then DeptString:= DeptString + 'Public Consulting Group' + chrw(13)
...


You will be checking the x'th item in array a at each iteration of the loop.

Edited by Keikoku - 18 May 2011 at 10:08am
IP IP Logged
<< Prev Page  of 3
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.017 seconds.