2015-08-02 12:12:44 +00:00
|
|
|
The {{KW|SPACE$}} function returns a {{KW|STRING}} consisting of a number of space characters.
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
2016-03-18 11:36:04 +00:00
|
|
|
:''result$'' = '''SPACE$({{Parameter|count&}})'''
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2021-02-18 17:11:22 +00:00
|
|
|
{{PageParameters}}
|
2016-03-18 11:36:04 +00:00
|
|
|
* {{Parameter|count&}} is the number of space characters to repeat. Cannot use negative values!
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
''Usage:''
|
|
|
|
* Semicolons can be used to combine spaces with text [[STRING]] or numerical values.
|
|
|
|
* [[Concatenation]] using + can be used to combine [[STRING]] text values only.
|
|
|
|
* Spaces are often used to erase previous text PRINTs from the screen.
|
|
|
|
* The function result can also be used to [[GET]] and [[PUT]] a number of bytes as zero characters: bytes$ = SPACE$(numbytes)
|
|
|
|
* Spaces can also be made using [[SPC]], [[CHR$]](32) or [[STRING$]](n%, 32).
|
|
|
|
|
|
|
|
|
2016-03-18 11:36:04 +00:00
|
|
|
''Differences between QB64 and QB 4.5:''
|
|
|
|
* '''QB64''' can use [[LONG]] values for count up to 2,147,483,647 while '''QB 4.5''' could only use [[INTEGER]] values up to 32,767.
|
|
|
|
|
|
|
|
|
2015-08-02 12:12:44 +00:00
|
|
|
''Example 1:'' How to space text in a [[PRINT]] statement using SPACE$ with string [[concatenation]].
|
|
|
|
{{CodeStart}} '' ''
|
|
|
|
{{Cl|FOR...NEXT|FOR}} count% = 0 {{Cl|FOR...NEXT|TO}} 3
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "abc" + {{Cl|SPACE$}}( count% ) + "def"
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|FOR...NEXT|NEXT}} count%
|
|
|
|
{{CodeEnd}}
|
|
|
|
{{OutputStart}}abcdef
|
|
|
|
abc def
|
|
|
|
abc def
|
|
|
|
abc def
|
|
|
|
{{OutputEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
''Example 2:'' In [[SCREEN]] 0 SPACE$ can be used to change the background color to make an American flag.
|
|
|
|
{{CodeStart}}
|
|
|
|
USA flag centered on screen with thin horizontal red & white stripes
|
|
|
|
' blue corner field with randomly twinkling stars
|
|
|
|
{{Cl|CLS}}
|
|
|
|
{{Cl|LOCATE}} 25, 1
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "Press any key to stop twinkling";
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|COLOR}} , 4
|
|
|
|
z = 15
|
|
|
|
{{Cl|FOR...NEXT|FOR}} x = 5 {{Cl|TO}} 19 '13 red & white stripes (x =5 to 21 for 15 stripes)
|
|
|
|
{{Cl|IF...THEN|IF}} z = 15 {{Cl|THEN}} z = 4 {{Cl|ELSE}} z = 15
|
|
|
|
{{Cl|COLOR}} , z
|
|
|
|
{{Cl|LOCATE}} x, 15
|
|
|
|
{{Cl|PRINT}} {{Cl|SPACE$}}(55)
|
|
|
|
{{Cl|NEXT}} x
|
|
|
|
{{Cl|FOR...NEXT|FOR}} x = 5 {{Cl|TO}} 11 'blue field in upper left quadrant (x = 5 to 13 to hold all 50 stars)
|
|
|
|
{{Cl|COLOR}} 15, 1 'sits above 4th white stripe
|
|
|
|
{{Cl|LOCATE}} x, 15
|
|
|
|
{{Cl|PRINT}} {{Cl|SPACE$}}(23)
|
|
|
|
{{Cl|NEXT}} x
|
|
|
|
DO
|
|
|
|
stop$ = {{Cl|INKEY$}}
|
|
|
|
{{Cl|FOR...NEXT|FOR}} x = 5 {{Cl|TO}} 10 {{Cl|STEP}} 2 '39 stars staggered across blue field (50 stars if x = 5 to 12)
|
|
|
|
w = 16
|
|
|
|
{{Cl|FOR...NEXT|FOR}} y = 1 {{Cl|TO}} 6 '5 rows of 6 stars
|
|
|
|
r = {{Cl|INT}}({{Cl|RND}} * 6)
|
|
|
|
{{Cl|IF...THEN|IF}} r = 0 {{Cl|THEN}} z = 31 {{Cl|ELSE}} z = 15
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|IF...THEN|IF}} stop$ = "" {{Cl|THEN}} {{Cl|COLOR}} z {{Cl|ELSE}} {{Cl|COLOR}} 15
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|LOCATE}} x, w
|
|
|
|
w = w + 4
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "*";
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|NEXT}} y
|
|
|
|
w = 18
|
|
|
|
{{Cl|FOR...NEXT|FOR}} y = 1 {{Cl|TO}} 5 '5 rows of 5 stars
|
|
|
|
r = {{Cl|INT}}({{Cl|RND}} * 6)
|
|
|
|
{{Cl|IF...THEN|IF}} r = 0 {{Cl|THEN}} z = 31 {{Cl|ELSE}} z = 15
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|IF...THEN|IF}} stop$ = "" {{Cl|THEN}} {{Cl|COLOR}} z {{Cl|ELSE}} {{Cl|COLOR}} 15
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|LOCATE}} x + 1, w
|
|
|
|
w = w + 4
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "*";
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|NEXT}} y
|
|
|
|
{{Cl|NEXT}} x
|
|
|
|
w = 16
|
|
|
|
{{Cl|FOR...NEXT|FOR}} y = 1 {{Cl|TO}} 6 '1 row of 6 stars
|
|
|
|
r = {{Cl|INT}}({{Cl|RND}} * 6)
|
|
|
|
{{Cl|IF...THEN|IF}} r = 0 {{Cl|THEN}} z = 31 {{Cl|ELSE}} z = 15
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|IF...THEN|IF}} stop$ = "" {{Cl|THEN}} {{Cl|COLOR}} z {{Cl|ELSE}} {{Cl|COLOR}} 15
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|LOCATE}} x, w
|
|
|
|
w = w + 4
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "*";
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|NEXT}} y
|
|
|
|
t = {{Cl|TIMER}}
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|DO...LOOP|DO}} {{Cl|WHILE}} t + .2 >= {{Cl|TIMER}}: {{Cl|LOOP}}
|
|
|
|
{{Cl|LOOP}} {{Cl|WHILE}} stop$ = ""
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|COLOR}} 7, 0
|
|
|
|
{{Cl|END}}
|
|
|
|
{{CodeEnd}}{{small|Code by Solitaire}}
|
|
|
|
:''Explanation:'' In [[SCREEN]] 0, the background color is only placed with the the printed text and spaces. [[CLS]] can color the entire screen.
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSeeAlso}}
|
|
|
|
* [[PRINT]], [[PRINT USING]]
|
|
|
|
* [[STRING$]], [[CLS]]
|
|
|
|
* [[SPC]], [[TAB]]
|
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageNavigation}}
|