Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: formula Post Reply Post New Topic
Author Message
tabmori
Newbie
Newbie


Joined: 14 Apr 2011
Online Status: Offline
Posts: 3
Quote tabmori Replybullet Topic: formula
    Posted: 14 Apr 2011 at 3:19pm
I have Crystal Reports 9 and I am trying to come up with a formula that would allow me to identify the following mistakes.  I have a report number field that contains one of these two formats: 7 numbers at the front and a letter at the end or 2 letters at the front and 6 numbers at the end.  Both have a total of 8 characters.  What I need is a formula that would pull out all the report numbers that does not conform to either of the two formats
Specifically, I want all report numbers that are either too short or are longer than the 8 characters.
 
Please help.
tabpsych
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 15 Apr 2011 at 2:21am
What are you trying to do with the numbers when you have them? Display them in the report footer? Highlight them in the details section?

You should be able to check the length of the field and return the value if it does not equal 8:

if len({table.field})<>8
     then  (whatever you want it to do)

If you're looking for the report to keep track of them and store it in a variable then you will have to create a string variable to store the numbers in. So something like:

whileprintingrecords;

global stringvar sIncorrectLength:=sIncorrectLength & (if len({table.field})<>8
     then {table.field} & ','
          else '';
sIncorrectLength;

For the above, you will have to create an Initialize formula that will reset the variable if you wish to display the strings depending on groups and you will need a Display formula that is independent from the Calculation formula so it displays it properly.

Hope that points you in the right direction.
|< /\ '][' ( )
IP IP Logged
tabmori
Newbie
Newbie


Joined: 14 Apr 2011
Online Status: Offline
Posts: 3
Quote tabmori Replybullet Posted: 15 Apr 2011 at 7:30am
Actually I wanted to identify the report numbers that were entered incorrectly.  The proper format of the field should be #######Alpha or
AlphaAlpha###### for a total of 8 characters.  I wanted to pull out all the incorrectly entered report numbers in a list form for audit purposes.
 
Basically I want to be able to pull out any report numbers that do not follow either formats.
tabpsych
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 15 Apr 2011 at 8:05am
Ideally, I would run through each character and check whether they're alpha or digit using regular expressions, but crystal doesn't support them.

The other method (which IMO is horrible) is to declare a global array of characters and check whether each character is in the array or not.

To make things a little better you I would assume

1: you will only have digits and letters
2: there will be NO symbols if they are not allowed

And then declare an array containing all 10 digits.
You will then loop through each character in the field and check whether they match the criteria or not.

Filter out all records where the length is not 8, and then run a formula that will check the actual characters afterwards.

But it sounds extremely slow.

Edited by Keikoku - 15 Apr 2011 at 8:06am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Apr 2011 at 8:15am
maybe
 
NOT(
(len({table.field})= 8 and
isnumeric(left({table.field},7)) and not(isnumeric(right({table.field},1))))
or
(len({table.field})= 8 and
isnumeric(right({table.field},6)) and not(isnumeric(left({table.field},1))) and not(isnumeric(mid({table.field},2,1))))
)
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 15 Apr 2011 at 9:31am
Oh, so there is such a function. Guess it's not too bad then.
IP IP Logged
tabmori
Newbie
Newbie


Joined: 14 Apr 2011
Online Status: Offline
Posts: 3
Quote tabmori Replybullet Posted: 18 Apr 2011 at 6:00am
Thank you for all who replied.  I tried the right and left function as suggested and it worked!
tabpsych
IP IP Logged
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.