Line breaks in DATA statements?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Line breaks in DATA statements?

Post by seaBiscuit$ » Tue Dec 12, 2006 9:54 pm

How can I put strings with line breaks in DATA statements? I could do something like this and PRINT it or store it in a variable:

"Hello," + chr$(13) + "World!"

but I can't use chr$ inside DATA statements. Is there any way I can put a string in a DATA statement with line breaks in it?

bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm » Wed Dec 13, 2006 2:34 pm

To be honest, i dont know any simple way to do that. Well, "simple" is pretty personal thing but as far as i know, there aint no quick trick to do that.

I would like to hear more what you are up with, maybe we can figure out some solution for this.

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Wed Dec 13, 2006 6:20 pm

seaBiscuit$ wrote:How can I put strings with line breaks in DATA statements? I could do something like this and PRINT it or store it in a variable:

"Hello," + chr$(13) + "World!"

but I can't use chr$ inside DATA statements. Is there any way I can put a string in a DATA statement with line breaks in it?
Right, you can't use chr$ inside a DATA statement.
However, you could use a seldom used DUMMY character, like a backslash (\) in the DATA statement, like:
DATA "Hello,\World!"

As you do the READ of the DATA statements, replace backslashes with a chr$(13) right after every READ, like:

Code: Select all

READ A$
for x=1 to len(A$) 
     if mid$(A$,x,1)="" then mid$(A$,x,1)=chr$(13)
next x
print A$
If your data has backslahes, which I doubt, then pick another dummy character, like & or ^ or |.

I tested it and it works.
Good luck.
Regards..... Moneo

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Post by seaBiscuit$ » Wed Dec 13, 2006 6:31 pm

I found a way to add line breaks. (sort of) If I want it to break after a certain word, I can just put spaces after it until it wraps the text on its own. That's a good idea to use dummy characters too! I could use that for other special characters, or if I get sick of putting lots of spaces in. Thanks! :D

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Wed Dec 13, 2006 7:06 pm

seaBiscuit$ wrote:I found a way to add line breaks. (sort of) If I want it to break after a certain word, I can just put spaces after it until it wraps the text on its own. That's a good idea to use dummy characters too! I could use that for other special characters, or if I get sick of putting lots of spaces in. Thanks! :D
Padding the words out with spaces works but it's rather clunky, plus you need to count the exact number of spaces needed.

Use the dummy character technique.

P.S.: "Seabiscuit" --- are you a horse racing fan?

Regards..... Moneo

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Post by seaBiscuit$ » Wed Dec 13, 2006 8:09 pm

moneo wrote:P.S.: "Seabiscuit" --- are you a horse racing fan?
You must have me confused with another Seabiscuit. :P
Alright, I'll use the dummy characters.

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Wed Dec 13, 2006 9:25 pm

seaBiscuit$ wrote:
moneo wrote:P.S.: "Seabiscuit" --- are you a horse racing fan?
You must have me confused with another Seabiscuit. :P
Alright, I'll use the dummy characters.
No, what I meant was that Seabiscuit was a famous race horse in the 1930's and 1940's. Books were written about him, and several motion pictures were made. He was one of the greatest race horses in America.

Thought you knew this.

P.S.: Glad you're using the dummy characters technique.

Regards..... Moneo

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Post by seaBiscuit$ » Wed Dec 13, 2006 10:18 pm

moneo wrote:No, what I meant was that Seabiscuit was a famous race horse in the 1930's and 1940's. Books were written about him, and several motion pictures were made. He was one of the greatest race horses in America.

Thought you knew this.
That's what I meant. I guess I should have made that clearer. I just thought Seabiscuit would be a cool name, though I haven't seen the movie yet.

Post Reply