Help with PRINT command...

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
Post Reply
misticalbobo
Newbie
Posts: 1
Joined: Sat Jul 14, 2007 11:56 pm

Help with PRINT command...

Post by misticalbobo »

Okay I'm new to programming and I'm making a text RPG Battler to practice coding. So I wanted to know if theres a way to make the text go down a line without doing this

PRINT "1. Attack"
PRINT "2. Defend"
PRINT "3. Magic"
PRINT "4. Escape"

Because that's the only way I know, lol. Just wondering if there's a more convenient way.
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

Unless you plan to print these four lines more than once, your way is the best way.

If you plan on printing those lines many times, this way is better:

Code: Select all

DIM P(4) AS STRING
P(1) = "1. Attack" 
P(2) = "2. Defend" 
P(3) = "3. Magic" 
P(4) = "4. Escape" 

Then, each time you need to print the above, you use:

Code: Select all

FOR I = 1 TO 4
  PRINT P(I)
NEXT I
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

If you're talking about a way to manually position text, what you want is the LOCATE keyword.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

I don't know why you would want to, but you could print a carriage return:

Code: Select all

PRINT "1. Attack" + CHR$(13) + "2. Defend" + CHR$(13) + "3. Magic" + CHR$(13) + "4. Escape" 
Erik
Veteran
Posts: 72
Joined: Wed Jun 20, 2007 12:31 pm
Location: LI, NY
Contact:

Post by Erik »

If you're looking for something similar to the C/C++ "\n" then see the post above me.

If you're going to be writing them out a lot, you could always create a sub called "DisplayBattleText" (or whatever) and store the text in there. Then just use a "CALL DisplayBattleText" in your program when you wanted it.

Locate command works as follows:

Code: Select all

LOCATE 5, 6 'that's y-pos, x-pos
PRINT "Where you stated in the previous command"
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

DON'T use CALL at all, it's 100% unnecessary. It's like using LET. :D
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

List of commands to avoid:

DEF FN (use FUNCTION instead)
WHILE (use DO WHILE instead)
LET (omit)
CALL (omit)

and more than likely many others...
Zoasterboy
Coder
Posts: 12
Joined: Thu Nov 02, 2006 3:51 pm
Location: Washington
Contact:

Post by Zoasterboy »

If you want to save lines, just use ":" like this

Code: Select all


PRINT "Menu": PRINT "1. Item One": PRINT "2. Item Two"

The ":" represents a new line.
-yah
Post Reply