Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Getting a specific number from a CSV to report Post Reply Post New Topic
Author Message
Anubisascends
Newbie
Newbie
Avatar

Joined: 05 Apr 2009
Online Status: Offline
Posts: 15
Quote Anubisascends Replybullet Topic: Getting a specific number from a CSV to report
     Posted: 06 Apr 2009 at 10:52am
Hello all,

I am working on updating another report and ran into a bit of a snafoo...

I have an access database that has a table called tbl_Profiles.  The database has, recently, had a new field added to it named 'ProfileSet'.  This new field is a boolean field that causes another field to contain different information.

In the table, there is a field named 'Shape'.  This field, typically, contains a comma separated value string that stores the following info:

Number of Points, point 1 x, point 1 y, point 2 x, point 3 y, .....point n x, point n y, etc.

Now, when the 'ProfileSet' field is set to true, the shape field's info changes to this:

Profile 1.ID, Profile 1.X, Profile 1.Y, Profile 2.ID, Profile 2.X, Profile 2.Y,.....Profile N.ID, Profile N.X, Profile N.Y, etc.

What kind of syntax can I use to get the Profile N.ID from the CSV string?

Thanks in advanced for any help you can provide.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Apr 2009 at 11:42am
is the profileN.id portion of SHape always a set # of characters from left to right in the string (assuming the profileset=t) or do the other values leading up to it change the total number of characters in the string?
IP IP Logged
Anubisascends
Newbie
Newbie
Avatar

Joined: 05 Apr 2009
Online Status: Offline
Posts: 15
Quote Anubisascends Replybullet Posted: 06 Apr 2009 at 12:06pm
The Profile.ID value won't be a set number of characters, but it will be a set number of commas...

For instance, if I have 3 Profile ID's (115, 94, and 3) the value of the the 'Shape' field will look similar to this:

115,0,0,94,1.5,2,3,2.5,3

The bold numbers are the profile id numbers that I need to get.  I write c# code and know that I could do something like this:

string[] s = [value].Split(',');

Then I could iterate through the given array and look for the first, fourth, seventh, and so on, values using a loop.  Can I do something similar in Crystal Reports?
IP IP Logged
Anubisascends
Newbie
Newbie
Avatar

Joined: 05 Apr 2009
Online Status: Offline
Posts: 15
Quote Anubisascends Replybullet Posted: 06 Apr 2009 at 12:08pm
btw - thanks for the response, sorry I forgot to say that...
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Apr 2009 at 12:44pm
Not exactly my strong suite here but at the very least you could create different formulas per item you wish to extract:
Stringvar Array x:= split({table.shape},",");
x [1]
Replacing the "1" with the value you want to extract (1, 4 and 7 in your example above)
Anyone else want to give the better process here Embarrassed
IP IP Logged
Anubisascends
Newbie
Newbie
Avatar

Joined: 05 Apr 2009
Online Status: Offline
Posts: 15
Quote Anubisascends Replybullet Posted: 07 Apr 2009 at 6:24am
So here is the code that I want to use:

// get an array of the numbers in the shape field
stringvar array idValues := Split({tbl_Profiles.Shape},",");
// initialize the result variable
booleanvar result = false;
// get the length of the idValues array
numbervar idLength = Count(idValues);
// loop through all of the id numbers
For i := 0 to idLength Do
(
  if idValues[i*3] = {Molding.Molding ID} then
  ( 
    result := true;
    exit for
  );
);
result


The problem is that it keeps telling me that I need to place a variable name after the For declaration.  For all of the examples I can find, I see no problems.

Thank you for the help.

BTW - this is going in the suppress formula for the details section of my sub-report, I figure I can just suppress all profile IDs that are not in the array.


Edited by Anubisascends - 07 Apr 2009 at 6:25am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Apr 2009 at 8:25am
OK i think you want to return a True if you find the CrownModling shape anywhere in the Shape field and False if it is not in there.
Again, not my area of comfort but I think the below will do that:
 

stringvar array idValues := Split(
{tbl_Profiles.Shape},",");
booleanvar result = false;
numbervar idLength = Count(idValues);
numbervar i;
For i := 0 to idLength Do
(
  if idValues =
{Molding.Molding ID} then
  ( 
    result := true;
    exit for
  );
);
result
 
You could also use an instring process to do the same thing.
if instr({tbl_Profiles.Shape},{Molding.Molding ID})>0 then True Else False
or just conditionally suppress on the >0
instr({tbl_Profiles.Shape},{Molding.Molding ID})>0


Edited by DBlank - 07 Apr 2009 at 8:26am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Apr 2009 at 8:56am
I should warn you that the instring may give you some false positives based on your data...
Example: If the moulding ID is "AB" it will find that anywhere in the string so if there is a part of that field that is "123ab" or "abcd" it would accept these as being part of the string and returna value >0...
IP IP Logged
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