Crystal Reports Training by Ken Hamady, MS, Reporting and Training Nationwide On Location TrainingPublic ClassesIndividual TrainingIntroductory Course OutlineAdvanced Course OutlineFormula ExamplesNewsletter Back IssuesMy BlogResource LibraryConsulting ServicesSupport ServicesContact InformationLinks to third party productsBack to main pageMy Credentials
Free Crystal Reports formula examples from KenHamady.com


To learn the techniques used in these formulas get:


The Expert's Guide to Crystal Reports Formulas
and
 Expert Techniques for Crystal Reports I, II & III

PDF exPLODE

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 enterprise or BO Enterprise because the file name is changed to a serial number at the time the report is published.)


This first example will work in version 8 - 11.  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 removes 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