In Introduction to Qbasic, It is a programming language made by Microsoft in 1991. QBASIC full form is Quick Beginners All Purpose Symbolic Instruction Code.
QBasic provides the platform called an Integrated Development Environment (IDE). Using QBasic, users can write, edit, and test their code. It uses very simple commands like “PRINT” to show messages on the screen, INPUT to take user input etc.
QBasic helps users learn important concepts of variables, loops, conditions, and creating small programs. It does not create .exe files. Instead, it creates .bas files, which can be run in the QBasic interpreter easily.
QBAISC was developed for DOS operating systems. It can also be run on PC having Windows Operating. It is very simple for teaching and learning the basics of programming.
QBasic helps learn basic structure of programming for logic and problem-solving.
Features of QBasic:
- It converts reserved words into uppercase if syntax is correct.
- It uses syntax similar to English which simplifies the writing of programs.
- It checks the syntax automatically.
- Program written in QBasic, can be logically broken down into manageable blocks.
- It can perform basic commands such as displaying text, allowing input and making graphics.
- It is very popular among educational institutions for introducing beginner programming concepts.
Disadvantages
- Structured programming is not developed.
- QBasic, which is based on DOS, is no longer in use except in educational institutions.
What is variable in QBasic?
Variable is defined as the container or space where the data are stored and changed during the program execution.
Rules for declaring variable name
- A variable name must start with an alphabet (A to Z) e.g. a10, B2, B$ etc.
- Variable names cannot contain spaces. We can use underscores to separate words if necessary.
- A variable name can be upto 40 characters long.
- We cannot use reserved keywords or commands (like PRINT, IF, THEN, etc.) as variable names.
- Variable name cannot start with “FN” because it is used for user-defined functions.
Declaration of variables
Implicit Declaration
Declaration of the variable at the place of assigning a value to a variable is called implicit declaration. We declare variable using suffix symbols (%, !, $, #, &)
Variables starting with A-H, O-Z: Single Precision (by default).
Variables starting with I-N: Integer (by default).
Example:
CLS
x = 10
name$ = "John"
PRINT x,
PRINT name$
END
Limitations:
- Implicit declaration can cause errors if you accidentally make a typo in a variable name.
- Tracking and managing variables becomes more difficult in large programs.
Explicit Declaration
We declare variable at the beginning of a program in explicit declaration. It reduces the repetition of variable name. Using DIM statement, we declare the variable in a program.
Example:
CLS
DIM x AS INTEGER
DIM name AS STRING
x = 10
name = "John"
PRINT x
PRINT name
END
Note: variable ‘x’ is integer/numeric variable and ‘name’ is string variable.
Type of a variable in QBasic:
Variable can store different types of data. Mainly, there are two types of variables. They are as follows:
Numeric Variable:
The variable that stores numeric data or numeric constant is called numeric variable.
e.g. A = 2, B = 2.5
Note: Here A and B are numeric variables that store 2 and 2.5 respectively. The values of numeric variables can be used in calculation. There are four types of numeric variables. They are
- Integer (we use % symbol, e.g. count%)
- Long Integer (we use ! symbol, e.g. value!)
- Single Precision (we use # symbol, e.g. Pi#)
- Double Precision (we use & symbol, e.g. BigNum&)
String Variable:
The variable that stores alphanumeric data or string constant is called string variable. Normally, the string variable is ended with dollar sign “$”.
e.g. A$ = “RAM”, CLASS$ = “ukg”
Note: Here A$ and CLASS$ are string variables that store “RAM” and “ukg” respectively.
Uses of a variable
After a variable is declared in a program, it can be displayed on the screen and be used in calculations.
CLS
A = 10;
B = 20;
TOTAL = A + B;
PRINT TOTAL ;
END
Output is: 30