FoxPro function: padl() and padr()

the FoxPro® function padl() adds characters to the left (=beginning) of a string, until a certain length is reached. It is very helpful when you want to print text adjusted to the right
Parameters:
1. the string2. final length
3. character to add
***************************** | |
* Tool&Task example program * | |
* padl_padr() * | |
* last compile: 24.11.2021 * | |
***************************** |
local ls, ln, longest, lx, lx, ldist, llines, lout | |
llines = 6 | |
dimension ls(llines, 2) |
&& 2 dimensional array, (6*2 elements) |
ls(1, 1) = "Apples" |
&& I sell .... |
ls(1, 2) = "2.20" |
&& this is a string! |
ls(2, 1) = "Oranges" | |
ls(2, 2) = "10.20" | |
ls(3, 1) = "Nuts" | |
ls(3, 2) = "3.20" | |
ls(4, 1) = "Sweet Peas" | |
ls(4, 2) = ".20" | |
ls(5, 1) = "Bananas" | |
ls(5, 2) = "7.20" | |
ls(6, 1) = "Sugar Stick" | |
ls(6, 2) = "1.20" | |
longest = 0 | |
for ln = 1 to llines |
&& find longest string in first array element |
if len(ls(ln, 1)) > longest |
&& assume you have 1,000 elements in a table |
longest = len(ls(ln, 1)) |
&& you will certainly use such a loop |
endif |
&& count the length of 'Sugar Stick' |
endfor | |
longest = longest + 2 |
&& add 2 spaces |
lx = 3 |
&& to explain the function |
ly = 3 |
&& string combines array elements |
ldist = 17 | |
ttg_new() |
&& clear TTG globals |
ttg_createbmp(148,148, FORMCOLOR) | |
ttg_font('G', 'Courier New', 9, '000', 100, 300, BLUE) | |
ttg_fontselect('G') |
&& not used by a print list |
for ln = 1 to llines |
&& the 6 * 2 elements |
lout = padr(ls(ln, 1), longest, ".") + padl(ls(ln ,2), 6, " ") | |
ttg_text(lx, ly, lout) | |
ly = ly + ldist | |
endfor | |