phone: (540)338-0194
email: ken@kenhamady.com

´╗┐

 Crystal Reports formula examples

Removing the path from the "File Path and Name" field:

One of my favorite special field is the "File Path and Name" field, which allows you to show the file name and complete path on the report output.   On occasions, the path to the file, especially a long path, is of little value and the file name without the path is all that is needed.   This allows use the file name as an automatically updated title.    The following formulas will strip the drive and path from the file name.   (NOTE - these formulas will NOT work in Crystal Server or BO Enterprise because the file name is changed into a serial number at the time the report is published.)

This first example will work in versions 8 and later.  It does not need to be modified when pasted into a report:

    filename [ InstrRev ( filename , '\') + 1  to Length (FileName) -4]


This second example is specifically for users with version 7 or older.   As written it can remove up to 8 levels of directory names from the file name and path.   You can even add more copies of the START and FILE line pairs to go further, if you have especially deep directories.

WhileReadingRecords;
StringVar File := FileName;
NumberVar End := Length ( File)  - 4 ;  // you can delete the "-4" if you want to see the .RPT  on the end
NumberVar Start := 4;

File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];
Start:= Instr (File, "\")+1;
File:= File [Start to end ];

file