
'************************************************
'                                               *
'  Routine to right justy numbers in a window.  * 
'                                               *
'                  By Andy.                     *
'                                               *
'************************************************

' This example allows up to 100 lines, but you can increase this by amending the variables
' string No[100]
' string rjb[100,100]

$include "windowssdk.inc"

'Variables needed in the right justify routine (needed)...
int rja = 0
int rjc = 0
int across,down,numbers = 0
int BoxNo = 0
int Longest = 0
int MaxLength = 0
int StartAcross = 0
int StartDown = 0
int MoveDown = 0
int MaxLinesPerCol = 0
int LineCount = 0
int ColCount = 0
int ColGap = 0
int Gap = 0
string No[100]
string rjb[100,100]
string Format
uint dwStyle = WS_VISIBLE | WS_CHILD | SS_CENTER

'Some numbers to right justify as an example...
double a = 0
double b = 0
double c = 0
double d = 0
double e = 0
double f = 0
double w = 0
double x = 0
double y = 0
double z = 0

a = 56.00
b = 764.42
c = 45234.10
d = 56.00
e = 200.15
f = 210.50
w = 8980.12  
x = 12.56
y = 1000.44
z = 142567.08

'Your window...
DEF w1 as WINDOW

OPENWINDOW w1,0,0,900,500,@MINBOX|@MAXBOX|@SIZE,0,"Right justify numbers.",&main

'Setup your format parameters...
Setup()

'Read your numbers in...This could be in a loop etc...
ReadNumber(a)
ReadNumber(b)
ReadNumber(c)
ReadNumber(d)
ReadNumber(e)
ReadNumber(f)
ReadNumber(w)
ReadNumber(x)
ReadNumber(y)
ReadNumber(z)

'Center & print the numbers...
CenterRight()
PrintNumbers(w1)

WAITUNTIL w1 = 0
END


SUB main( ),INT

SELECT @MESSAGE

    CASE @IDCONTROL

        SELECT @CONTROLID


        endselect

	 CASE @IDCREATE
		   centerwindow w1

    case @IDCLOSEWINDOW
         closewindow w1
         end 

endselect

RETURN 0

ENDSUB

'***************************************************************
'                                                              *
' Sub routines to right justify and print numbers to a window  *
'                                                              *
'***************************************************************      

Sub Setup(),int 

	 BoxNo = 1000 'Display static controls begin at this number (or any you want). 
	 MaxLength = 10 'Maximum length of a possible number including commas etc.
	 StartAcross = 50 'Starting across position on screen.
	 across = StartAcross
    StartDown = 50 'Starting down position on screen.
	 down = StartDown 
    MoveDown = 15 'Spacing between each line.
	 Gap = 8 'Spacing between each individual numbers (depends on font size used).
    ColGap = 160 'Spacing between columns.
    Format = "###,###.##" 'Format of how you want the numbers to be displayed.
    MaxLinesPerCol = 0 'Maximum lines per column, use 0 (zero) for only one column.

return 0
endsub

'Find the length of the longest number & specify the number format you require...
sub ReadNumber(double NumberIn),int 

    Numbers += 1
	 No[Numbers] = ltrim$ using(Format,NumberIn)

    if len(No[Numbers]) > Longest
       Longest = len(No[Numbers])
    endif

return 0
endsub


'Offset the numbers to the right...
sub CenterRight(),int

for rjc = 1 to Numbers

    int Offset = 0
    Offset = Longest - len(No[rjc])

    int ab = 0

	  for rja = Offset+1 to MaxLength
         ab = ab + 1
         rjb[rjc,rja] = mid$(No[rjc],ab,1)
	  next rja

next rjc

return 0
endsub

'Create statics & print the numbers...
sub PrintNumbers(window WinIn),int 

	 for rjc = 1 to numbers '(Lines)

        LineCount += 1

        'You can use something to start each line off here (optional)...
		  CreateWindowEx(0,"STATIC",chr$(163),dwStyle,across-25,down,10,20, WinIn.hwnd,BoxNo+1000,GetModuleHandle(0),0)

        'Print the numbers...
		  for rja = 1 to MaxLength
			   BoxNo += 1
			   CreateWindowEx(0,"STATIC",rjb[rjc,rja],dwStyle,across,down,10,20, WinIn.hwnd,BoxNo,GetModuleHandle(0),0)
			   across += Gap
		  next rja

        if LineCount = MaxLinesPerCol
           LineCount = 0
           ColCount += 1
           down = StartDown  
        else
           down += MoveDown
        endif
 
        across = StartAcross + (ColCount * ColGap)

	 next rjc

return 0
endsub



