• Print

Author Topic: What is SPACE$?  (Read 81 times)

davidshq

  • Newbie
  • *
  • Posts: 24
What is SPACE$?
« on: November 16, 2012, 09:17:26 PM »
I'm looking at some old QuickBasic code and have something that looks like this:
Code: [Select]
SPACE$(68)What in the world does this mean? I haven't been able to find any articles explaining SPACE($).
Thanks.

SMcNeill

  • Hero Member
  • *****
  • Posts: 2414
    • Email
Re: What is SPACE$?
« Reply #1 on: November 16, 2012, 09:23:49 PM »
It's a CHR$(32) character.  (SPACE)

So Space$(68) is a string of 68 spaces.   Good for formatting text for printing or displaying.  :)
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.
http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

http://bit.ly/DataToDrive - A set of routines to quickly and easily get data to and from the disk.  BI and BM files

davidshq

  • Newbie
  • *
  • Posts: 24
Re: What is SPACE$?
« Reply #2 on: November 16, 2012, 09:28:24 PM »
Thanks! That is very helpful. One question, if I put in code like this:

Code: [Select]
LOCATE 9,1 : PRINT SPACE$(79) : PRINT "hello"
Shouldn't the result be 79 spaces into the screen? It is right at the edge?

Dave

SMcNeill

  • Hero Member
  • *****
  • Posts: 2414
    • Email
Re: What is SPACE$?
« Reply #3 on: November 16, 2012, 09:40:14 PM »
Depending on font, screen resolution and all that stuff.

Of course, you're printing and then printing hello on the line below.

Try this:
Code: [Select]
FOR I = 1 TO 20
   PRINT SPACE$(I);
   PRINT "Hello World
NEXT

I think that should help you see how it works.  ;)
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.
http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

http://bit.ly/DataToDrive - A set of routines to quickly and easily get data to and from the disk.  BI and BM files

davidshq

  • Newbie
  • *
  • Posts: 24
Re: What is SPACE$?
« Reply #4 on: November 16, 2012, 09:56:12 PM »
Thanks!
Dave

mcalkins

  • Hero Member
  • *****
  • Posts: 1269
    • qbasicmichael.com
    • Email
Re: What is SPACE$?
« Reply #5 on: November 17, 2012, 04:28:04 AM »
The QB64 wiki allows you to look up keywords alphabetically, and by usage.
http://www.qb64.net/wiki/index.php?title=Main_Page

Quote from: davidshq on November 16, 2012, 09:28:24 PM
Code: [Select]
LOCATE 9,1 : PRINT SPACE$(79) : PRINT "hello"

1: You forgot the semicolon, so, as SMcNeill, pointed out, you are not requesting the cursor to stay on the same line after the first PRINT.
2: The QBASIC/QB64 PRINT statement will print the string on the next line if it doesn't fit on the first line.

Code: [Select]
PRINT SPACE$(78); "h"
PRINT SPACE$(78); "he"
PRINT SPACE$(78); "hel" ' 2 strings, and the second doesn't fit.
PRINT SPACE$(78) + "hello" ' 1 string

By using + to concatenate the 2 strings into 1, the PRINT statement gets it as one string, and prints the whole thing.

Regards,
Michael
The QBASIC Forum Community: http://www.network54.com/index/10167 Includes off-topic subforums.
QB64 Off-topic subforum: http://qb64offtopic.freeforums.org/

  • Print