06-08-2022, 07:26 PM
Right align a number input:
Code: (Select All)
_Title "Right align a number input to a column number" ' b+ 2022-06-08
'expecting numbers up to 10 digits including dot or minus sign for this demo
Locate 5, 10: Print "Number 1:" ' column 19 leave blank if max 10 digits used
Locate 6, 10: Print "Number 2:"
a = getNumber(5, 30)
b = getNumber(6, 30)
t$ = Str$(a + b)
Locate 7, 10: Print " Total:"
Locate 7, 30 - Len(t$): Print t$
Function getNumber (row, lastDigitCol) ' might need to control length of output
k$ = InKey$
While k$ <> Chr$(13)
If Len(k$) Then
If InStr("-123456789.", k$) Then
num$ = num$ + k$
Locate row, lastDigitCol - Len(num$) - 1: Print Space$(Len(num$));
Locate row, lastDigitCol - Len(num$): Print num$;
ElseIf Asc(k$) = 8 Then
If Len(num$) Then
num$ = Left$(num$, Len(num$) - 1)
Locate row, lastDigitCol - Len(num$) - 1: Print Space$(Len(num$));
Locate row, lastDigitCol - Len(num$): Print num$;
End If
End If
End If
k$ = InKey$
Wend
getNumber = Val(num$)
End Function
b = b + ...