Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Split Function Error Post Reply Post New Topic
Page  of 2 Next >>
Author Message
phimtau123
Newbie
Newbie


Joined: 10 Mar 2009
Online Status: Offline
Posts: 22
Quote phimtau123 Replybullet Topic: Split Function Error
     Posted: 23 Jun 2009 at 3:55pm
Hello All,
 
I have a share variable that store a string delimited by "/" and I want to split the string into an array. And store each of the subscript in different separate field. 
 
So I have the following questiong:
 
1)How can i set up the array?
2)Make the array share between formula?
3)how can I access the different part of the array and put them into different field?
 
So my current approach is as follow:
 
Formula1: In detail section(suppress)
 
Shared stringVar HDModel;
WhilePrintingRecords;
(
if recordnumber =1 then
(
HDModel:={HDModel.Name};
)
else
(
HDModel:=HDModel+' / '+{HDModel.Name};
)
);
 
Formula 2: In Footer (also suppress) 
THis is where I dont know how to set up the array to store the string.
 
Shared stringVar HDModel;
Share StringVar Array Model := Split(HDModel, "/");
 
But I keep getting a "output cannot be part of an array" error for formula2. What am I doing wrong?
 
 
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 24 Jun 2009 at 12:00am
Hey Phimtau123
 
I could be compleet wrong on this but ..
If the first record is for example "Human" in the hdmodel.name then your HDModel is value "Human"
If the next record is then in example "male" you would get
HDModel = "Human/Male"
 
Is there a reason why you want to add them in 1 field in the first place and then later on try to split them ?
Why not make a formula
IF recordnumber = 1 THEN
 hdmodelRec1 := {hdmodel.name}
ELSE
 hdmodelrec2 := {hdmodel.name}
 
you can make then a formula
HDMODEL := hdmodelrec1+'/'+hdmodelrec2
 
this way there is no need to split it any more later on
 
Not sure if this is whay you needed but hope it helps
 
Greets
 
Adam
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 24 Jun 2009 at 6:35am

try declaring the array variable and then in a separate line assign the value.  You can declare the array shared, or you could recreate it, since the string is shared.  I am not a big fan of arrays, because I can't 'see' the values in Crystal...also silly to note, but the array is not declared Shared, it is Share...if this is the exact code, that might have something to do with it.

Adam: He is building a string to display something in the footer.  If there are 40 details, he is not going to build 40 shared variables...and the number may well be indeterminate. So a delimited string is not a bad solution.
 
As for accessing the array and putting them into their own fields, you can't.  You can build formulas for each part of the array, but if each part is known, ie there is only a fixed number of items, then I am with Adam, why not just put them into shared variables and access them that way (you would have to build formulas for each one, as it is, to be able to access them on them on the report).
 
HTH
IP IP Logged
phimtau123
Newbie
Newbie


Joined: 10 Mar 2009
Online Status: Offline
Posts: 22
Quote phimtau123 Replybullet Posted: 24 Jun 2009 at 12:01pm

well you are right lockwelle the number of row is undetermine. it could range from 1-14 row for each record. Well the reason why i went with array was because that was a good approoch at the time but it didnt meet the requirement. My boss wanted it to seperate into each field.

So if I was do go the ugly way and created 14 different variables. How would I go about setting that up?
 
Can I just go like:
IF recordnumber = 1 THEN hdmodelRec1 := {hdmodel.name}
IF recordnumber = 2 THEN hdmodelRec2 := {hdmodel.name}
 
Up to 14?
 
 
I'm very bad at scripting and very new to crystal report. So any help/advice here is good.
 
Thank you
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 24 Jun 2009 at 12:08pm
Well, you need the declaration part:
shared numbervar hdmoddelRec1;
 
if you are using Crystal syntax, you need ; at the end of each line (except the last)
 
How do you know the recordnumber?  You might need a variable for that as well, and you would need 14 other formulas to display each variable on the report, luckily they are really simple...something like:
shared numbervar hdmodelRec1
 
If the values are ever reset, you will need a formula to reset them, and if you need to do aggregates, you will probably need a formula for each aggregate as well as a variable to accumulate for the aggregates...yes there a lot of formulas that will be accessed, I use cut and paste and change the variables inside of a formula like the one outlined in your post.  To duplicate formulas, I use Crystal and right click on the formula and select duplicate, and then I go in and modify it.
 
HTH
IP IP Logged
phimtau123
Newbie
Newbie


Joined: 10 Mar 2009
Online Status: Offline
Posts: 22
Quote phimtau123 Replybullet Posted: 24 Jun 2009 at 2:42pm

I'm a bit confuse: So I would need to create 14 different formula and in each would be

Formula1:
shared stringvar hdmodelRec1;
IF recordnumber = 1 THEN hdmodelRec1 := {hdModel.Name}
Formula2:
shared stringvar hdmodelRec2;
IF recordnumber = 2 THEN hdmodelRec2 := {hdModel.Name}
 
and insert each formula into the footer? or detail? would it make a different?
 
Well wouldnt that mean if the recordnumber is 1 then return  hdModel.Name but if the recordnumber is 2 then return nothing.
 
Also when the recordnumber is 2 then formula1 would be blank and formula two would return hdModel.Name but it would return the first hdModel.Name not the second one.
 
Dunno if i'm making any sense here lolz
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 25 Jun 2009 at 6:05am
Yes and no.  Actually for the details, you would have 1 formula like:
shared stringvar hdmodelRec1;
shared stringvar hdmodelRec2;
...
IF recordnumber = 1 THEN hdmodelRec1 := {hdModel.Name};
IF recordnumber = 2 THEN hdmodelRec2 := {hdModel.Name};
...
 
Where you need the 14 formulas is in the display, which is probably the footer....Each formula would like (but the variable would change):
shared stringvar hdmodelRec2
 
If these variables change every time a group changes you would have 1 more formula for the group header that would look like the one in the detail section but would look like:
shared stringvar hdmodelRec1;
shared stringvar hdmodelRec2;
...
hdmodelRec1 := 0;
hdmodelRec2 := 0;
...
 
In general, the one that I said is in details, you want where the data is going to be read, headers and footers are only accessed once per group, but the details are accessed by every data read that Crystal does.
 
Actually, when the record is 2, formula1 would be skipped/blank.  Formula 2 would assign the value, which since it is a different row in the data set would be the value for second one.
 
HTH
IP IP Logged
phimtau123
Newbie
Newbie


Joined: 10 Mar 2009
Online Status: Offline
Posts: 22
Quote phimtau123 Replybullet Posted: 25 Jun 2009 at 9:52am
We are getting so close :)
 
So now I have 1 formula in detail (supress):
shared stringvar hdmodelRec1;
shared stringvar hdmodelRec2;
shared stringvar hdmodelRec2;
...
IF recordnumber = 1 THEN hdmodelRec1 := {hdModel.Name};
IF recordnumber = 2 THEN hdmodelRec2 := {hdModel.Name} else dhmodelRec2 := 'NULL';
IF recordnumber = 3 THEN hdmodelRec3 := {hdModel.Name} else dhmodelRec3 := 'NULL';
...
 
And 14 formula in the footer with:
shared stringvar hdmodelRec1
...
 
This seem to work fine for the item that have 2 or less hard-drive. When there a item with 3 hard-drive I would get this.
HD1......NULL.........HD3
OR 4 Hard-drive would get me this:
HD1.......NULL........NULL........HD4
 
Did I do something wrong?
 
Also I dont understand your last formula for the header:
shared stringvar hdmodelRec1;
shared stringvar hdmodelRec2;
...
hdmodelRec1 := 0;
hdmodelRec2 := 0;
...
 
You hdmodelRec is a string but you are assigning it to a 0?
One last question what is the different between the '=' and ':='
 
 
 
 
 
 
 
IP IP Logged
phimtau123
Newbie
Newbie


Joined: 10 Mar 2009
Online Status: Offline
Posts: 22
Quote phimtau123 Replybullet Posted: 25 Jun 2009 at 10:13am

I think that the NULL statement is making hdmodelRec2 and hdmodelRec3 as NULL? The reason I put that in there is because i keep getting duplicate when there are more than one hard-drive.

For example: when there are two hard-drive for the FIRST time then it would be find as it will return

HD1....HD2
 
But after that if there are item with just 1 hard-drive then it would still return
 
HD1....HD2(last item value, repeating until the next real HD2) When it should display this:
HD1....Blank
 
Is there some tweak to the code that I need to do?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 25 Jun 2009 at 2:46pm

I wouldn't have placed this in the supress area, but that shouldn't affect anything.  The else NULL is killing all the prior settings, there shouldn't be an else.

As to the :=0, it should be :="".  = is a comparator operator, while := is an assignment operator.
 
the reason for the drive2 showing up in a 1 drive system is that the variables were not reset, which is the last formula where all 14 variables are set to "" ( := "" ).  You would clear the variables whenever the, i guess, computer changes.
 
IP IP Logged
Page  of 2 Next >>
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