Monday, 2024-05-06, 8:15 PM

Welcome Guest | RSS

MainRegistrationLogin
Qbasic Home

Catalog categories
Qbasic Tutorial [31]

Rate my Site
Rate JPSor Site
Total of answers: 168

Main » Articles » Qbasic Tutorial

Chapter 3 - Qbasic Tutorial

It was probably a bit hard to find your messages on the screen with that last program. Wouldn't it be nice to be able to clear all that stuff off the screen? "CLS", which stands for CLear Screen, is just the ticket. You will need to put CLS at the very top of your program to clear the screen before you print anything.

Inserting a new line at the top.

To make CLS the first line of your program, follow these steps:

  • Press the <Home> key to get to the beginning of the current line.
  • Press the <Up Arrow> key once or twice to get the cursor to the top of the program.
  • Press the <Enter> key to get a new line.
  • Press the <Up Arrow> key once to get the cursor on the new blank line.
  • Type CLS

Now your program should look like this:

 CLS
PRINT "Welcome to QBASIC. Your wish is my command."
PRINT "Programming is fun."

Run it. Remember, click on Run and then Start in QBASIC's menu. You can also run the program by pressing the <Shift> key and holding it down while pressing <F5> (that's what Shift+F5 means on the menu). Another handy shortcut.

That's much better. Only your message is on the screen, which is the way it should be.

Learned

  • CLS
  • Shift+F5

REM or '

Syntax:
REM comments
' comments

Purpose:

To add documentation comments (remarks) into a program without affecting the program flow. Also used for temporarily removing lines of code for troubleshooting.


Simple programs, typically less than a page long, do not usually require documentation. Once programs include subroutines and many page of programming, commenting (remarking) the code is a good practice. Remarks make no difference to the program but do help the programmer to make sense of the program. Labeling a section of code by explaining its purpose is a good tool for troubleshooting and for understanding what the program is and how it works in general.

 REM This program is very simple
CLS
PRINT "The QBasic Station"
REM The End
END

The apostrophe (') is a substitute for REM. It does the exact same thing, but is shorter to type. (Maybe the writers of QBasic saw that they had an extra character to use, so they did.)

 ' This program is very simple
CLS
PRINT "The QBasic Station"
' The End
END

Something to note is that remarks are the only type of lines that are allowed before the SUB sub_name and FUNCTION function_name lines in subroutines and functions. If an attempt is made to add lines ahead of the SUB or FUNCTION definitions, the QBasic editor will show an alert that this is so.

Commenting code well takes practice and is very rewarding during times of troubleshooting. To help you become an expert remarker, here are some tips on using the REM (or ') statement:
    - Comment large FOR...NEXT loops, explain what they do.
    - Comment any range-controlling sequences. (1 < x < 10)
    - Use several remark lines at the beginning of subroutines, to explain their "big picture" purpose.
    - Comment anything that looks like just a bunch of numbers, such as PSET, DRAW, LINE, and CIRCLE statements
    - But don't go overboard, remarking every single line in the program.



Source: http://jpsor.ucoz.com
Category: Qbasic Tutorial | Added by: JPSor (2009-02-26) | Author: JPSor
Views: 2935 | Rating: 3.0/2 |
Login

Qbasic Clock

Search

Visit my Friends

Who's Online

Total online: 1
Guests: 1
Resgistered: 0


Copyright MyCorp © 2024