Thursday, June 12, 2008

VFP Reporting Tip - paying it forward

I was mentoring one of our clients this morning because of a reporting issue he faced with some weird truncating labels (not that this tip is of any help for his problem {g}). During the session he showed me this new wiz-bang function he created to concatenate text together to be displayed on the report. He mentioned how his function removes the missing details from a snail mail address. You know the drill, customer wants to track address line 1 and 2, contact name and company name, but only wants to print the things that are filled in.

I turned around and told him about his new friend the semi-colon (;). This is a trick I learned back probably in FoxPro for Windows or even DOS when I was creating labels for customer mailings. You first drop a textbox on the Report/Label designer and size it to show the max lines you will print based on all the data being entered in the record. You can add the expression like this:

cCustomerName;cCompany;cAddress1;cAddress2;ALLTRIM(cCity)+",",cState,cPostalCode;cCountry

The semi-colon acts as a carriage return and any columns in the expression that are empty are not printed and if the line is empty the carriage return is not included. The commas (,) outside of a quote are replaced by spaces. So you can see how I am concatenating the city, state, and postal codes for a line.

I know this is an old trick and tip, but my client has been using Fox of some sorts for a long time too so in the case where you did not know this I am hoping it will be helpful. There are so many little things like this I take for granted that everyone knows, but realize in working with other Fox developers that this is not always the case. I also wonder from time-to-time how many little tips like this one I don't know about.

Labels: , ,