[futurebasic] FN LSET$ / FN RSETS

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2001 : Group Archive : Group : All Groups

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Sun, 21 Oct 2001 15:56:03 -0400
Some programming languages have LSET and RSET commands that allow a
programmer to easily adjust the right and left alignment of
fixed-length lines by padding with spaces or another character.

Alain Pastor has contributed the following examples of LSET and RSET
in FB^3 to be included in the FB^3 Rosetta Stone Library which, BTW,
is growing quite large. (Line width and the padding character in
Alain's example is set with a string created with FB^3's built-in
STRING$ function. Try adjusting the 31 and " " parameters to
experiment with the function.)

"The Rosetta Stone" web site offers these comments about LSET and RSET:

"Assigning a string larger than the fixed string size using LSet or
RSet will simply truncate the rightmost excess characters. For
example, if the variable phrase is a fixed string that can hold three
characters, both

LSet phrase = "abcde"

and

RSet phrase = "abcde" will set phrase to "abc".

"LSet and RSet seem to be "legacy" commands -- hangovers from the
QBASIC/GW-BASIC/BASICA days that have been left in Visual Basic for
backward compatibility with legacy applications written in those
older languages.

"Since they are meant to align characters within fixed-length
strings, they have meaning only when used with fixed-length strings
(with regular variable-length strings, LSet and RSet are the same
function -- they simply assign a string to a string variable)."

Ken

10/21/01

Please watch for e-mail line breaks and lost constant underscores.

'---------- BEGIN FB^3 CODE ----------

'~LSET/RSET

// Contributed by Alain Pastor

LOCAL MODE
LOCAL FN LSET$( srcStr AS STR255, dstStr AS STR255 )
DIM i AS INTEGER

LONG IF dstStr[0]
FOR i = 1 TO dstStr[0]
LONG IF i <= srcStr[0]
dstStr[i] = srcStr[i]
XELSE
dstStr[i] = _" "
END IF
NEXT
END IF
END FN = dstStr

LOCAL MODE
LOCAL FN RSET$( srcStr AS STR255, dstStr AS STR255 )
DIM i AS INTEGER

LONG IF dstStr[0]
FOR i = dstStr[0] TO 1 STEP -1
LONG IF srcStr[0]
SWAP srcStr[srcStr[0]],dstStr[i]
srcStr[0]--
XELSE
dstStr[i] = _" "
END IF
NEXT
XELSE
srcStr[0] = 0
END IF
END FN = dstStr

DIM myStr  AS STR255
DIM fitStr AS STR255

myStr  = "Hello world"
fitStr = STRING$(31," ")

PRINT:PRINT "FN RSET$ aligns this string to the right margin, ¬
padding the line with spaces:"
PRINT FN RSET$( myStr, fitStr )

PRINT:PRINT "FN LSET$ aligns this string to the left margin, ¬
padding the line with spaces:"
PRINT FN LSET$( myStr, fitStr )

'---------- END CODE ----------