Changing page numbers to letters

Monday 24 March 2014 @ 10:13 am

I was in a forum and someone asked if there were a way to change numbers into letters (1=A, 2=B, etc).  I had recently done something like this for a customer and was surprised that I had not posted the formula here.  You can apply this formula to any number that doesn’t go over 26.  This first version checks and prints a blank for numbers above 26.

if pagenumber in 1 to 26
then CHR (pagenumber + 96)
else ”

The number 96 in the second line gives you lower case letters.  Use 64 if you want upper case letters.

One special thing my customer needed was to have the the letters start over after 26, so that 27 was another ‘A’ and 28 was another ‘B’, etc.  To do this we used a remainder:

Local NumberVar x:= remainder (pagenumber- 1 , 26) + 1 ;
CHR (x + 96)

You might wonder what the +1/-1 is for in this formula.  This is the simplest way I found to get the exact multiples of 26 show as 26 instead of zero.

(For examples of my most popular formulas, please visit the FORMULAS page on my website.)







Leave a Reply

Jeff-Net
Recrystallize Pro

Crystal Reports Server