BB___SPACE

=SPACE$= toc

Description
> Returns a string of //number// space characters " ", (ASCII 32).

Syntax

 * 1) space$(//number//)

Hints
> SPACE$ is useful for formatting text. It can be used to produce formatted output to a file or a printer. See example.

> SPACE$ has the effect of moving the cursor or printer head a specific number of spaces, from the point where it is invoked, as specified by //number//.

> SPACE$ can be used to embed spaces into your string by using concatenation. (eg: "John" + space$(5) + "Smith" produces "Johnmedia type="custom" key="6799841"Smith").

> See also TAB, which is similar to SPACE$, but differs in these ways. TAB does NOT embed spaces into your string. TAB is only valid in PRINT statements and moves the cursor or print head to the column position specified by //number//, useful for columnar formatting.

Example
code format="lb" ' Concatenate names and membership and format the output dim name$(3), className$(3) name$(1) = "John L. Sullivan" name$(2) = "Ruth Bader" name$(3) = "George Kline"

for i = 1 to 3 nameLen = len(name$(i))

input "Enter membership category for "; name$(i);": "; mem$

className$(i) = name$(i) + space$(20-nameLen) + mem$ next i

for y = 1 to 3 print className$(y) next y

end code

Justifying Text
(works for monospaced font (Courier etc) only. Though, mainwin usually uses monospaced font.) code format="lb" ' Using SPACE$ in user-defined functions to justify text print "|"; LeftJustify$(30, "left"); "|" print "|"; CenterText$(30, "center"); "|" print "|"; RightJustify$(30, "right"); "|"

end

function LeftJustify$(FieldWidth, Text$) ' adds spaces to the right and ' trims the result to the fields width

if len(Text$) > FieldWidth then LeftJustify$ = Text$ else LeftJustify$ = left$(Text$ + space$(FieldWidth), FieldWidth) end if end function

function CenterText$(FieldWidth, Text$) ' adds spaces to both sides of the text ' and trims the result to the fields width

if len(Text$) > FieldWidth then CenterText$ = Text$ else padding = int((FieldWidth - len(Text$)) / 2) CenterText$ = left$(space$(padding) + Text$ + space$(FieldWidth), FieldWidth) end if end function

function RightJustify$(FieldWidth, Text$) ' adds spaces to the left and ' trims the result to the fields width

if len(Text$) > FieldWidth then RightJustify$ = Text$ else RightJustify$ = right$(space$(FieldWidth) + Text$, FieldWidth) end if end function code