QBASIC Statements:
Any command or the instructions in the QBASIC is called a statement. Statements are classified into executable and non-executable. Executable statement specify actions and non-executable statements specify characteristics, arrangements and initial values of data.
Some of the QBASIC statements are:
- CLS
- REM
- INPUT
- LET
- END
- PRINT USING
- LINE INPUT
- LPRINT AND LPRINT USING
- READ….DATA
- RESTORE
- LOCATE
- SWAP
It clears the previous output from the display screen and makes the screen blank.
Syntax: CLS
REM or Remarks is non-executable statement where single quotation(‘) is used.
Syntax: REM <remark>
It receives input from the keyboard during the execution of the program.
Syntax: INPUT [“Message”] ; Variable
It is used to assign the value in the variable.
Syntax: LET [variable] = [expression]
It is used to display the output on the screen. Question mark (?) also can be used instead of PRINT command to display on the screen.
Syntax: PRINT[expression][{; | ,}]
It is used at the end of the QBASIC program to terminate it.
Syntax: END
Syntax: PRINT USING “formatting string”; expression
! | Displays only the first character of string |
\n\ | Prints first n+2 characters from the string |
& | Displays all the string |
# | Digit position is spacified |
&& | Prints leading & sign |
^^^^ | Prints the number in exponential format |
. | Decimal point position specification |
Example:
CLS
a$ = “Rudra”
b$ = “Bahadur”
c$ = “Rai”
PRINT USING “!”; a$; “.”;
PRINT USING “!”; b$; “.”;
PRINT USING “&”; c$;
END
This statement allows to input line of data at a time and assign in to single variable.
Syntax: LINE INPUT “string”; string variable
Example:
CLS
LINE INPUT “please enter the data”; n$
PRINT n$
END
9. LPRINT and LPRINT USING Statement
LPRINT statement is used to print the text to a printer
LPRINT USING statement is used to print formatted output to a printer.
Example:
CLS
a$ = “this is a test message”
LPRINT a$
END
Example:
CLS
A = 98765.4321
LPRINT USING “###,##,##”; A
END
It is used in conjunction with the DATA command which lets QBASIC to read data. It is used mostly when dealing with large quantities of data in program.
Example:
CLS
READ a, b, c
PRINT a, b, c
DATA 10,20,30
END
Example:
CLS
READ E, C, N, S
T = E + C + N + S
P = T / 4
PRINT “the total is”; T
PRINT “the percentage is”;P
DATA 60,80,80,90
END
Once the data element is read, it cannot be read again until the program resets it. The RESTORE statement is used to reset the data in the program.
Example:
CLS
READ a, b, c
PRINT a, b, c
RESTORE
READ d, e, f
PRINT d, e, f
DATA 10,20,30
END
It is used to move the cursor to the specified position on the screen.
Example:
CLS
LOCATE 11, 45
PRINT “Hellow World”
END
[11,45: ROW 11 and COLUMN 45 ]
The SWAP is an assignment statement. It exchanges the values of two variable.
Example:
CLS
INPUT “Enter the first number”; a
INPUT “enter the second number”; b
PRINT “Before using SWAP”; a, b
SWAP a, b
PRINT “After SWAP”; a, b
END