Introduction To QBASIC - Online Article

BASIC stands for Beginners of All purpose Symbolic Instruction Code.

BASIC was developed at Dartmouth College by John Kemeny and Thomas Kurtz in the mid 1960s. BASIC is the best way to start or learn programming. Its user friendly, fun and very easy to learn! Even Bill Gates concurs with that statement!

To be frank you cannot be categorized as a 'developer' if you start coding in basic, but it's your first step to. Yet never underestimate BASIC. It's very powerful and lot can be done with it. All it needs is a creative mind and some programming skills that you will eventually learn in this tutorial. It will help you to know and understand the logic of programming and design of algorithms.

There are many versions of basic available starting from BASICA, GWBASIC to a more advanced QBASIC. In this tutorial you will be taught to code in QBASIC. QBASIC stands for Quick BASIC. It has its own compiler and comes with its own IDE.

Guidelines

Each instruction of a QBASIC command is provided in a separate statement. Therefore, the complete program is composed of a sequence of statements. These statements are executed in order of there appearance in the program unless a deliberate 'jump' statement is given.

Every statement must appear in a separate line. A statement cannot exceed one line in length. Blank spaces and empty lines may be inserted where ever desired to improve the readability of the program.

• QBASIC is user friendly.
• QBASIC is flexible.
• QBASIC is universally available.
• QBASIC's commonly used features are standard.

Getting Started

1. Run the application QBASIC.exe
2. Go to FILE and click on NEW.
3. A new window will appear named UNTITLED.BAS
4. And you can start coding right away!

Character Set

The set of characters used in QBASIC is given in the table below.

Alphabets A, B, C, D................Y, Za, b, c, d..............y, z. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ~ ! @ # \$ % ^ & * ( ) _ + | - = \ ` [ ] { } : " > < ? , . / ; ' [ ]

Constants

Numerical quantities in QBASIC are referred to as constants. They can be of two type integer and decimal. Some points about constants that have to be kept in mind.

• Commas cannot appear anywhere in numbers.
• A number can be preceded by a + or - sign.
• A number cannot contain an exponent. Though, exponents can be expressed by the letter 'E' which replaces the base 10. (E.g. 1.2*10-3 = 1.2E-3).
• A constant can have at most 9 significant figures.
• The constant can have value ranging from 10-38 to 1038 including 0.

Examples:

```0		=	+0			=	-0
1		=	+1			=	0.1E+1
-5280	=	-5.280E+3	=	-.5280E4
3000000=	3E6			=	3 E+6 ```

Strings

A string is a sequence of characters (alphabets, digits and special symbols). Black spaces may be included in a string but not quotation marks (""). Some versions of QBASIC allows up to 4095 characters in a string.

Examples:

```HARRY
Gold\$
\$123.45
X1= 123
Enter the value of a:
Do you wish to continue?```

Variables

• A variable is a name that represents a number or a string.
• To represent a numerical variable letter can be used.
• To represent a string variable the letter has to be followed by a dollar sign.

Example:

```Numerical variable
A	g	H1	kI8		NUM9
String variable

Operators

Special symbols are used in QBASIC to represent arithmetical, logical and comparison operations.

Arithmetical operators

• Subtraction -
• Multiplication *
• Division /
• Exponential ^

Comparison operators

• Equal to =
• Not equal to <>
• Less than <
• Less than equal to <=
• Greater than >
• Greater than equal to >=

Precedence

1. Parenthesis ( )
2. Exponential
3. Multiplication & division

Assigning values - The LET statement

The LET statement is used in assigning values to a numerical or string variable. We can define a variable in this manner in a program.

Syntax:

`LET variable = value`

Example:

```LET A = 12

Taking an Input from the user - The INPUT statement

The input statement is used to enter a numerical or string data during the program execution.

Syntax:

```INPUT variable
INPUT "your string goes here"; variabale```

Example:

```INPUT A
INPUT "Enter the value of X "; A ```

Displaying the Output - The PRINT statement

The PRINT statement is used to display a data on the output screen. The output data can be numbers, strings or formulas. Successive item must be separated by semicolon (;) or commas (,).

Syntax:

```PRINT "your output goes here"
PRINT variable ```

Example:

```PRINT "This is a test run"
PRINT A ```

Terminating the program - The END statement

The END statement is used to end a program. The program does not execute after it encounters an END statement.

Syntax:

`END`