LOCATE question

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
DWolf
Coder
Posts: 10
Joined: Fri Aug 25, 2006 3:58 am

LOCATE question

Post by DWolf » Fri Aug 25, 2006 4:01 am

Hi all,

I know how to use the basics of the LOCAT Row,Column statement however I have a quick question about it.

I want to print the character "0" on a new line after my last PRINT statement. However due to things previous in the program this line may not always be the same so I can't set the Row and Coumn to a definite position.

So how to I locate the previous PRINT statement and put the character on a new line after that?

NOTE: Due to what I am trying to do here I cannot just use another PRINT Statement as I am creating an animation by making the character move. Thanks for any help.

User avatar
The Walrus
Veteran
Posts: 85
Joined: Fri Apr 01, 2005 7:19 am
Location: Denmark
Contact:

Post by The Walrus » Fri Aug 25, 2006 11:16 am

Look up the CSRLIN and POS functions in the qb help file, they should do the trick. You can use them to determine where on the screen the cursor is.
If swimming is so good for your figure, how do you explain walruses?

DWolf
Coder
Posts: 10
Joined: Fri Aug 25, 2006 3:58 am

Post by DWolf » Fri Aug 25, 2006 5:55 pm

Well, my code is:

Code: Select all

FOR Counter = 0 TO 60
row = CSRLIN
LOCATE row, 1
PRINT "0"
SLEEP 1
LOCATE row, 1
PRINT " "
LOCATE row, 2
PRINT "0"
NEXT Counter
So you can see I want the 0 to jump back and forth between coulmn 1 and 2. However at the moment when it loops around it just starts a new line (yes I need a loop here). How can I keep it all on the same line?[/code]

AiRMaN
Coder
Posts: 14
Joined: Sat Aug 19, 2006 11:28 pm
Location: Jordan

Here's one way to do it!

Post by AiRMaN » Sun Aug 27, 2006 4:42 am

I think you went coding without any planning at all!, from what I understood, you want to creat a primitive animation of a "0" that jumps between Column 1 and 2, here's the code for it,

Code: Select all

CLS
row = CSRLIN             ' Set 'row' to the current Row location
FOR Counter = 0 TO 60 
LOCATE row, 1            ' Set cursor position to row and column 1 
PRINT "0"                ' Print '0'
SLEEP 1                  ' Wait a sec or a key press
LOCATE row, 1            ' Again locate row and column 1
PRINT " "                ' Erase '0'
LOCATE row, 2            ' Locate row and column 2
PRINT "0"                ' Print '0'
SLEEP 1                       
LOCATE row, 2            ' Locate row and column 2 again
PRINT " "                ' Erase '0'
NEXT Counter
END
~AiRMaN~

Post Reply