QB004 - Comments In QBasic

Languages : QBasic
Tools : QBASIC.EXE
Statements : REM
Prerequisites : Install QBasic (from Tools CD #3 \ Microsoft Tools (part 2 of 2) \ QBasic - simply copy it onto your hard disk)
Estimated time : 5 minutes

Introduction

Sometimes it's useful to put a note or reminder in the 'source code' of software you write. It's a good way to save time later when you may be looking back at some old code and wondering to yourself "I wonder why I did it that way", or worse yet, "I wonder what on earth that was supposed to do!!!".  :o)  Comments in code is a good and simple way to record when you started working on a project, when various changes were made (and what those changes were), as well as documenting reasons for taking seemingly strange approaches to solve the problem at hand.

Every computer programming language has it's own 'syntax' for leaving comments in the code, and in most languages there are actually a handful of ways you can choose between depending on things like whether you want just one line of comment or whether you want a large block of text across multiple lines.

In QBasic, there are two main ways of leaving comments in your source code.

The REM Statement

REM stands for "REMark" - i.e. it lets you leave remarks (comments) in your code. Here's how to use it :


Self explanatory

The Apostrophe

In very early versions of BASIC, REM was the only 'proper' way to leave comments. QBasic introduced a second and much more flexible way of achieving the same thing. Simply put an apostrophe at the end of any line, and any text after the apostrophe is ignored, allowing you to make comments not only on otherwise blank lines but also on lines with other code.

Using Comments

I have long been in the habit of beginning every program with a few comments saying who made the program, when he started making it, and a brief description of what he was hoping to achieve. You'll be surprised how quickly a few years pass and you can look back on these comments and they form something of a diary.


Every program I write begins with something that looks like this...

Conclusion

And that's all there is to it, folks! It really is that simple! No homework. We'll see you at the next lesson! :o)

Copyright (C) Jonathan Field 2004
Version 20041024Wed
Comments / Suggestions