Q-BASICS 


👉Learning Plan

After  complete reading this blog, you will be able to:
  • define the programming language
  • introduce QBasic Programming
  • tell the features of QBasic Programming
  • describe about the QBasic editor screen
  • explain about the QBasic elements
  • write about the operators used by QBasic

👀Introduction

A computer program is a collection of instructions that performs specific task when executed by a computer. A computer requires program to function, and typically executes the program instructions in a central processing unit. A programming language is a notation for writing program. A computer program is usually written by a computer programmer in programming language. A computer does not understand any language except machine language. The data and instruction given to the computer in the user language must be translated into machine language to understand by the computer. Translation of computer language is possible with the help of translator program only. There are three types of language translators and they are compiler, interpreter and assembler.

QBasic Programming

QBasic is a high level programming language developed by Microsoft Corporation in 1985. It is modular programming language where program is divided in different modules or procedures. The process of breaking the large programs into separate modules or part is called modular programming. Modules or Subroutine is a sequence of program instructions that performs a specific task. They can be used in programs wherever that particular task should be performed. QBasic is easy to learn as it uses English like keywords and mathematical symbols to write a program. It has two types of window on a same screen. They are program window and immediate window.

Program Window

 The upper window is titled as 'Untitled' is the window where you write program. This window is called program window. To see the output of the statements written in this window , you can press Shift+F5 key.


Immediate Window

The lower window which is titled as 'Immediate' is known as Immediate Window. It is the window to test commands, expression, etc. As soon as the enter key id pressed, it displays the output on the screen.


Features of QBasic

  • It is simple and easy to learn.
  • It checks syntax automatically.
  • It capitalizes the reserved words(Keywords) automatically.
  • It allows you to break lengthy program into modules.
  • It interprets a statement of program at a time to CPU.
  • It has dynamic program debugging feature.
  • It supports local and global variables.
QBasic Loading

QBasic programming language consists of two files: QBASIC.EXE and QBASIC.HLP. Normally these files are found in a folder named 'QBASIC' which is in drive C: or may in a other drive where you saved.


To start QBASIC, follow the following steps.

  •  Click on the start button
  • Point to All Programs and then Accessories.
  • Select Command Prompt, it displays Command Prompt Window.
  • To move to the root directory, at DOS prompt, Type CD\ and Press the Enter Key.
  • At C:\> prompt, type CD QBASIC and press the Enter Key.
  • At C:\ QBASIC> prompt, type QBASIC and press the Enter Key. It will display QBASIC welcome screen as below.
  • Press the ESC key to get the QBasic editor screen.

Some Important Memory bytes to Remember:

  • QBASIC editor is the working window where you write programs.
  • Menu bar has various of list of commands like File, View, Search, Run, Debug, Options and Help.
  • The status bar shows short cut keys and the location of the cursor on the screen.
  • If you want a new program, you need to remove the previous program from the program window.
  • The upper window which is titled as "Untitled" is the window where you write program is called Program Window.
  • The lower window which is titled as "Immediate" is known as Immediate Window.

Elements of QBASIC 

Every programming language consists of some basic elements which are required to construct a QBASIC program. The element required to construct a QBASIC  program consists of  a set of characters, keywords, constants, variables, operators and expressions.

Character set

A set of characters that are allowed to use in QBASIC is known as the QBASIC Character Set. The QBASIC Character Set consists of alphabets(both small and capital), numbers(0to9) and special characters. These special character sets are =, +, -, <>, /, *, (), %, $, #, &, etc.

Keywords

Key words are those words which have special meaning in QBASIC. Keywords are formed by using characters of QBASIC Characters Set. Keywords are statements, commands, functions and names of operators. 

Data types in QBASIC. 

 Data type is the indicator that tells us what kind of value must be stored in a variable, like if we want to store number in a variable so its data  types is numeric. Every variable used in the program has data type. There are five types of variables. Each one has its own associated suffix to identify its type.

1. String(S$)- This variable stores alphabets or alphanumeric values and is indicated by a $(dollar ) sign after the variable name as suffix, It can also store number  but they cannot be used for doing mathematical calculations.

String length:        minimum value = 0 characters
                              maximum value = 32,767 characters

2. Integers(N%)- This variable stores number with no fractional part i.e. non-decimal number.  It is indicated by a percent sign(%) after the variable name as suffix. It occupies 2 bytes of space in memory. 

Integer length:       minimum value = -32,768 numbers
                              maximum value = 32,767 numbers 

3. Long Integer(N&)- This variable also stores integer value i.e. non-decimal number. It is indicated by  &(ampersand)sign after the variable name as suffix. It 4 bytes of space in the memory.

Long integer length:     minimum value = -2,147,483,648 number
                                      maximum value = -2,147,483,647 numbers

4. Single Precision Number(N!)- This variable can store Single- Precision values i.e. decimal or non decimal numbers up to 7 digits. It is indicated by !(exclamation) sign after the variable name as suffix. It occupies 4 bytes of space in the memory.

Single precision length:         minimum value = -3.37*10^(38)
                                               maximum value = 3.37*10^(38)

5. Double Precision Number(N#)- This  variable can store Double Precision values i.e. decimal as well as non decimal numbers up to 15 digits and stores 8 bytes of space in memory. It is indicated by #(hash) sign after the variable name as suffix.

Double Precision length:     minimum value = -1.67*10^(308)
                                             maximum value = 1.67*10^(308)

Variable and Constant:- 

Variable: A location or address  for storing values are variables. Variable can be up to 40 characters long. There are two types of variable, numeric and string. A variable that stores numbers are numeric variable for e.g. A,NUM, xyz are numeric variable. A variable that stores alphanumeric values are string variable it is indicated by $ sign for e.g. A$, NUM$, xyz$.
Constant: A fixed value of a variable that remains same during the execution of program are constant. They are the values of variable like 10,20,3.14, "Ram", "Pokhara" and so on.

QBasic Operators

An operator is a symbol which tells the computer to perform certain mathematical an logical calculation. these are the special symbols or words used to describe an operation or an action which is to be performed between two or among more than two values.

Types of Operators

  1. Mathematical Operators/ Arithmetic Operators.
  2. Relational Operators
  3. Logical Operators

Fig: Mathematical Operators



Fig: Relational Operators 


Fig: Relational Operators

Expressions

An expression is the combination of operators, constants and variables that is evaluated to get a result, The result of the expression is string data, numeric data or logical value(1 or 0) and can be stored in a variable. For example,

Fig: Expression in QBasic