Know what you are returning
I just solved a problem, which took too long to identify...so I though I would pass along the experience.
I created a calculation field called NamesBoth, which was simply NameLast & ", " NameFirst
I had a script that wrote a layout to both a PDF and XLS.
The problem was that in the spreadsheet, the calculated field was populated with a "0" but the PDF was fine.
After some time I figured out that when I created the calculated field, I was "returning a number" and not "text."
If your fields are behaving "strangely" or "not as expected" ensure that the field is returning what you expect/want/need.