What are QB64 statements?
To communicate with a computer, every programming language has its specific keywords and syntax. QB64 also has its own keywords and syntax, which are used in giving instructions to the computer.
Every command and instructions in QB64 is called as QB64 statements.
In this post, we will go through some QB64 statements along with their QB64 syntax and examples.
If you want to read about QB64 or its advantages you can go through “Introduction to QB64 and its Advantages” so that you will have the idea and the basic understanding of the QB64 software and the Qbasic programming language.
So, let’s start with the list of QB64 statements,
1. REM Statement
REM statement is used to give remarks in a program. The computer does not execute this statement. Whatever is written after REM is ignored by the computer. REM command can be used anywhere and many times in a program. It is a good practice to use the REM statement at the start of the program to define its purpose.
REM THIS IS QB64 PROGRAM
2. PRINT STATEMENT
The PRINT statement in QBasic is used to display any message or result on the screen. Any text written in double-quotes is printed as such. Anything written without quotes is treated as a program component and its value will be displayed.
The PRINT command can be used in different variations to print with the output in different formats.
PRINT WITH SEMI-COLON(;)
PRINT with a semicolon is used to display the values one after another, without any space in between.
Syntax: PRINT (Variable);(Variable);(Variable);..
LET X$ = “MY NAME”
LET Y$ = “IS”
LET Z$ = “RIA”
PRINT WITH COMMA(,)
The PRINT statement is used to display the values one after another with plenty of spaces(normally 14) in between. So, only five values can be printed in one line. In the case of more than five values, the remaining values will be printed on the next line.
Syntax: PRINT (Variable),(Variable),…
LET X= 78
LET Y= 22
Z = X + Y
PRINT X, Y, Z
PRINT WITH TAB FUNCTION
The TAB functions are used to move the print position to the column indicated in its argument. This PRINT statement is quite suitable for printing tabular type of results as output.
PRINT TAB (C); “Constant/Variable/Expression”
Where C is the number of column number
PRINT TAB(18); “GOOD EVENING”
Ths message “GOOD EVENING” will be printed on the screen, 18th column onwards.
REM “TAB FUNCTION PROGRAM”
PRINT TAB(10); “NAME”; TAB(20);”MARKS”
PRINT TAB(10); “RAMAM”; TAB(20);62
PRINT TAB(10); “MANAS”; TAB(20);90
PRINT TAB(10); “KABIR”; TAB(20);92
PRINT TAB(10); “RIDHIMA”; TAB(20);98
3. INPUT STATEMENT
The INPUT statement in QB64 is used to accept a data item from the user and store it in a variable. This statement asks the user to enter data by displaying a question mark (?) during the execution of the program. The program execution is suspended until the user enters the required values and press the Enter key.
INPUT <Numeric or String Variable Name>
You can have a list of variables in an INPUT statement, but they should be separated by commas. The corresponding values which you key in should also be separated by commas.
PRINT NAME$, CLASS, SCHOOL$
While using the INPUT statement, the computer performs the following tasks:
- It stops further execution of the program.
- It prints a question mark on the screen.
- It waits for the user to key in its response and presses the Enter key.
- It stores or assigns the same data item into the corresponding variable mentioned in the INPUT statement.
INPUT STATEMENT USING NUMERIC VARIABLES WITH MESSAGES
To make the input user friendly, the INPUT statement can also be used with an optional message, separated from the variable using a semicolon(;).
PRINT “Enter Marks”
SUM = M+C+E+S+H
PER = (SUM/TM)*100
INPUT STATEMENT USING NUMERIC AND ALPHANUMERIC VARIABLES WITH MESSAGES
The INPUT QB64 statement can be also be given both numeric and alphanumeric variables. Let us observe with the help of the given examples.
Write a QB64 program to calculate the total cost of pens:
INPUT “The pen you want to buy=”;P$
INPUT “Cost of 1 pen=”; C
INPUT “Total number of pens required=”; R
Total = R*C
PRINT “Total cost=”;Total
4. END STATEMENT
The END statement is used to indicate the end of a program. Any statement written after END will not be executed.
LET A = 2
LET B = 2
C = A+B
PRINT “THE ANSWER IS”,C
These are some of the most used QB64 statements that will help you to write a program in QB64. You can check “QBasic Statements and Commands“. There we have covered what is external and internal Qbasic commands and along with some Qbasic statements.