Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fixed Length Field

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hi

I am using Crystal 8.5 with an odbc database on a Windows XP/SP2 computer.

I want to create a fixed width field report. I found some threads where this was discussed but I can't seem to get it to work - what format do I save it in?

Specifically had problems with the name field. I have a name field where the name is presented as Smith, John and I want to split out as first name and last name. Also, if the person has a middle name I want to omit that altogether and only have first and last. So if the person's name was Smith, John Joseph I only want John.

Also, what if I want a "filler" field for the report with nothing in it? For example, the people requesting the data and specifying the format want salutation field if applicable. For me it's not applicable but it still has to be the first field with 4 characters.

Any and all help is greatly appreciated.

Shelby
 
Do it by stages. Split surname from forename/forenames using the comma, if this is reliably present in your data. Then split forename/forenames using space, taking the first or only result.

As for 'fillers', you can insert a blank text object at the right point.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Hi Madawc

Can you please be more specific i.e. show me the formulae to use? Thanks.

Shelby
 
@Surname
Code:
Split({F01.Mangr}, " ")[1]

@Forenames
Code:
Split({F01.Mangr}, " ")[2]

@Forename
Code:
Split(@Forenames, ",")[1]

Or you could concatonate, put one statement in another, like @Forename
Code:
Split((Split({F01.Mangr}, " ")[2]), ",")[1]

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Hi

Sorry but I still can't get this to work.

For surname I create the field of LastName using:
Split({ACABSTRACT.PATIENTNAME},",")[1]

Then I create the fixed length field of LName:
numbervar requiredlength:=25;
numbervar currentlength:=length(trim({@LastName}));

if currentlength<requiredlength then
trim({@LastName})+replicatestring(" ",requiredlength-(length({@LastName}))) else
if currentlength>requiredlength then
left({@LastName},requiredlength)

This works fine.

For Firstname I created a formula:
Split({ACABSTRACT.PATIENTNAME},",")[2]

Then I created the formula of FName:
numbervar requiredlength:=25;
numbervar currentlength:=length(trim({@FirstName}));

if currentlength<requiredlength then
trim({@FirstName})+replicatestring(" ",requiredlength-(length({@FirstName}))) else
if currentlength>requiredlength then
left({@FirstName},requiredlength)

However, when I place the field of FName in the report I get an error "A subscript must be between 1 and the size of the array".

What am I doing wrong? Thanks.

Shelby


 
You must have some instances that aren't split with a comma or where there is not a first name. Try changing {@firstname} to:

if ubound(split({ACABSTRACT.PATIENTNAME},",")) > 1 then
split({ACABSTRACT.PATIENTNAME},",")[2] else
""

Then your {@FName} formula should work, and you should be able to see what's going on.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top