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.
Joined: 22 May 2009
Online Status: Offline
Posts: 347
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.
Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
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.
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
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)))) )
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