6.2.3. Programming in QBASIC

 Back  Programming  Next

Programming can be accessed in several ways. Let's say that your source code is a unique entity, or that the entire code is divided into the main section and sub-programs separate from the base code or they call other programs to perform tasks for the program is made. Regarding simplicity here will show only the first option.

The first command that will be used is the CLS.

 QBasic - CLS Command
Figure 6.2.9 Help-screen of keyword CLS.

Her task is to erase the image in the window in which the program runs. It would be very awkward if the program is to start from the beginning, to see the prints of the previous launch. But sometimes you may need to delete the text and leave the photo prints. Then they will use one of the options with the keyword CLS. Description of the screen in Figure 6.2.9 indicates that the QBASIC mucus layer to display on the screen and one for text and one for graphics, as it is a two transparent images over one another (analogous to the two films on the an overhead projector). So help out to see that you can not write the command 'CLS 1 2' because it does not allow syntax (curly brackets).

Another statement of significance is CLEAR.

 QBasic - CLEAR Command
Figure 6.2.10 Help-screen of keyword CLEAR.

Why put this command immediately on startup? Specifically QBASIC command RUN / START from ToolBar is not the same as a return to the first command line with the command RESTART. RUN sets the variable to the default value (zero, of course), and the program back to the first line does not, and in the case of return to the execution of the program from the beginning, without interruption, it can happen that some variables are preserved, but the calculated value, and would thus total number of students was doubled and the 'weight' has 'twice' as big, if you would be guided by the description of the previous pages.

Each program code has a beginning and an end. To define the end of the program code used command END.

 QBasic - END Command
Figure 6.2.11 Help-screen of keyword END.

If this command is not inflicted by executing program code would not, for example, closed all the files being accessed. That would be when you restart the program could prevent access to any of the already open file because it is already 'occupied' (deny access). Unless specified after the command END followed by sub-programs that are very useful if you are invited to more places from the main program, and the same programming code does not have more time to write. However, we should distinguish END and END IF are not the same thing. The first command stops the program and another is program structure within the program that begins with the IF keyword. Thus, within the main program code can be more closure program structures, but only one END of the program. Inside the main program code is not a good use END command to stop the program works in more places.

So, according to this from the beginning of the basic structure of a program would be the following picture:

 QBasic program code
Figure 6.2.12 Methods of writing code in QBASIC.

QBASIC allows writing code with and without the numbers in front of each command. To help realize further examples will be presented with the numbers in front of each line of the program. Line number is not important, important is the correct sequence of commands. For example, 10, 20, 90 is the same as it is written 1, 2, 9 but was then too little space to add commands between 2 and 9 Therefore, it is better to use larger numeric ranges.


All presented in Chapter 6.2 is just a short instruction how to get started QBASIC programming tool. It is necessary to use the Help-displays and appreciate the proper choice of variables. To make it easier to find their bearings can be defined in advance who will be the type of variables that begin with a certain letter. Thus, for example, can determine that all numeric variables of type 'integer' have initial letters 'I-K' and 'M-N'. In addition to 'long integer' begin with the letter 'L' and 'O'. Furthermore, a 'double-precision' variables starting with the letter 'D-E' and 'single-precision' with the letter 'F-G', constants should always have the first letter 'A-C', and the text 'string' variables have the first letter 'R-S'. In this way, should not be added to the suffix variables that begin with a defined initial letters. Other at will.

According to the above previous figure small addition would make the following program code:

      10 CLS        ' Command to clear the screen
      11 CLEAR      ' Command to delete the contents of all variables
      12 DEFINT I-K, M-N
      13 DEFLNG L, O
      14 DEFDBL D-E
      15 DEFSNG F-G
      16 DEFSTR R-S
      17 CONST CPI = 3.14592927#
      20 REM Than this number further starts the program code
      999 END        ' Completion of the programming code
      1000 REM Than this number further start sub-programs

Defined by the initial letters for different types of variables, and according to the syntax of Figure 6.2.7 comments have been added to the program lines 10, 11 and 999. Lines 20 and 1000 have keyword REM suggesting comment (remark).


 Content - Home
 Content  Informatics Alphabet
Citing this page:
Radic, Drago. " IT - Informatics Alphabet " Split-Croatia.
{Date of access}. <http://www.informatics.buzdo.com/>.
Copyright © by Drago Radic. All rights reserved. | Disclaimer