Professional Documents
Culture Documents
Qbasic Program
Qbasic Program
PROGRAM
INTRODUCTION
CHAPTER 1: BASIC DEFINITION OF QBASIC
We can easily develop software and games, create enterprise, corporate and
business applications and software with databases and good visuals using the
Qbasic programming language.
It is even used in big banking and financial systems to design some of the
modules.
But once you learn Qbasic, it will be easy for you to learn other programming
languages like, java, python, c++, JavaScript etc.
We have two of the most popular Qbasic-compatible compliers for modern PCs
for windows.
They are free basic and QB64, both of which are compatible with the most
recent Windows versions.
To get started with Qbasic, go to qb64.org and download the stable version of
qb64, which also offers a support community
It is compatible with the most recent versions of Windows, Linux, and mac OS.
FEATURES OF QBASIC
Qbasic’s syntax is simple for beginners to understand, and errors are simple to
spot.
By merging small modules, we can create large applications that are then
integrated into the main system
The fact that QBASIC is easy to program and considerably simpler to port
between apps to one of its key advantages.
3. Fewer requirements:
Qbasic is a straightforward language that uses lower resources and has fewer
system requirements compared to other programming languages.
It is also a straightforward and simple language to learn and has many benefits for
newbies.
4. Free to use:
As Qbasic is open source software, it can be used free. It is a beginner friendly
programming language.
But you can download qb64 from their official website to run Qbasic on our
computer
First, open your browser on your pc and search qb64 download as shown below.
After you search for “qb64 download”, new interface will appear on your
screen as shown below.
Open the official website of qb64 to download a legitimate and
trusted Qbasic interpreter.
You can see the list to download the qb64 go with the latest stable
version of qb64.
You will be redirected to the download link for qb64 and download according
to your operating system.
Once download is completed, you can run qb64 on your pc.
If you face any problem while installing qb64 on your pc, you can ask questions
in forum.
Go to the forum section of this app and ask your question to the community.
Run Qbasic Programs
To start QBasic, first you should have QBasic installed on your PC.
In our case we had just downloaded qb64 program, so you don’t have to worry
about qbasic.
Click on the folder where you extracted the downloaded zip file
And finally click on .exe file or the application file as shown in figure below
Then the Qbaic development window appears
Press the ESC key to clear the welcome message
If you don’t want to install a built-in compiler on your computer or laptop.
You may always use online compliers from websites like tutorials point,
replicat.com etc
The variable which is used to store only string Some rules while giving variable
data is called the string variable. names are as follows;
A string variable can store numbers as well as The first character of a variable must
characters. The string data should be closed by
double quotation marks(“………”). begin with alphabets and the
remaining letters can be letters,
The string variable is represented by an alphabet
followed by a dollar sign($).
numbers or decimal points.
Here names$ and address$ are string variables.
Variables can be up to 40 characters
They store Ram and Kathmandu respectively. in length
CLS There cannot be space between the
Names$ = “Ram” variable name.
Address$ = “Kathmandu” String variable names must end with
PRINT “Name”; Name$ a dollar sign($)
PRINT “Address”; Address$ QBASIC keywords or reserved
END
words cannot be used as variable
names such as cls, input, print.
Some of the valid string variables in qbasic names
X, y, role_number, grade, salary, age, Num1, etc.
are:
Some invalid numeric variables in qbasic names
X$, y$, Names$, address$, sec1$, and so on.
are:
Some of the invalid string variables in qbasic
1x, mark sheet, name$, cls etc.
names are:
X, z, 3age$, name$, class 5$, cls$, input$, and so
on.
Some o valid numeric variables in qbasic names
are:
CONSTANTS
NUMERIC CONSTANTS
The constants are used to store the values which
A numeric constant is a constant which is used
are not changeable during the program execution
to store only numeric data.
time.
CLS
That means we have to declare constants to those
values which should not be changed by the Const pi = 22/7
program while it is running normally.
Const g = 9.8
Constants is similar to variables but the values
PRINT “pi”
can’t be changed or altered. In QBASIC, constants
are of two types: PRINT “g”
Numeric constants END
String constants Example; here, pi and g are numeric constants
and they store values 22/7 and 9.8
respectively.
Note: the constants are declared by using the CLS
keyword const. the constants declared before the
Const Names$ = “Ram”
program starts.
Const Address$ = “Kathmandu”
PRINT “Name”; Name$
STRING CONSTANTS
PRINT “Address”; Address$
the constants used to store only string data is called
the string constant. END
A string constant can store numbers as well as Here names$ and address$ are string
characters. constants. They store values Ram and
The string data should be closed by double Kathmandu respectively.
quotation marks(“………”). Note: CONST keyword is used for declaring
constant
CHARACTER SET For example:* means multiplication, and it is used
to multiply two operands
Character set refers to the set of characters that are
allowed to be used in QBASIC. The characters used in QBASIC are:
Alphabets (both uppercase and lowercase), numbers Alphabets: uppercase (A, B, C, D…….X, Y, Z)
(09), and special characters are all included in and lowercase(a, b, c, d,…..x, y, z)
QBASIC character set.
Numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
The special characters have their own meaning and
Special characters: +, -, *, /,=, <, >, (, ), {, },
function.
[, ], ;, :, “, ‘, \@, #, $ %, ^, &, _, |, and so on
QBASIC keywords and variables are formed by
using the characters defined in the QBASIC
character set.
OPERATORS ARITHMETIC OPERATORS
A symbol that is used to perform an operation Arithmetic operator refers to the operator which is
between two operands is called operator. used to perform mathematical calculations such as
addition, subtraction, multiplication etc.
An operator symbolizes what kind of operation has
to be performed on the data. Arithmetic operator/ please connect to internet
In QBASIC, four types of operators are used, which
are as follows:
Arithmetic operators
Relational operators
Logical operators
String operators
RELATIONAL OPERATOR
Relational operator refers to the operator which are
used to compare two values. These operators are
used to show relation.
The relational operator is also known as comparison
operator.
The result of the relational operator is always true
or false
Relational operator/ please connect to the internet
LOGICAL OPERATOR
Logical operator refers to the operator which is
used to perform logical operations such as AND,
OR, NOT etc.
It is used to combine two or more relational
expressions.
STRING OPERATOR
It gives a single value, that would be either true or • String operator refers to the
false. operator which is used to perform
Logical operators are specially used for making string operations such as
decisions. concatenation etc.
• The string operator is used to
combine two or more strings.
KEYWORDS The keywords can also be called Reserved Words.
Keywords are the reserved words that instruct the The QBASIC keywords can be classified into the
computer to perform certain actions. following four categories. They are:
Every programming language has its own keywords.
In the same way, QBASIC also has its own Assignment Keywords
keywords.
Input/output Keywords
Some of the examples of QBASIC keywords are
Control flow keywords
INPUT, CLS, PRINT, etc
Declaration keywords
PRINT:
REM:
This keyword is used to display the output on the
The REM is used to add comment anywhere in the screen.
program. We can also use question marks(?) instead of the
print statement.
Syntax: PRINT “string”
Example: Example:
PRINT “hello world” CLS
END INPUT “enter your name”, name$
Example: PRINT “hello” + name$
PRINT 234 END
END
LET:
INPUT: This keyword is used to assign a value to a variable.
The LET statement allows us to assign any value to
This keyword is used to input the value from the user
a variable
and store it in a variable when the program is
running. Syntax: LET
Syntax: INPUT “string”, variable
Example: END:
CLS It is used to terminate the execution of a program.
The END statement is typically used at the end of
LET a = 10 the program to stop further execution.
PRINT a
Syntax: END
END
Example:
Example:
CLS
LET name$ = “Dinga vinga”
PRINT “I am learning Qbasic programming
LET installs = 45000 language”
LET users= 10000 END
If else statement
If condition then The if else statement is used to execute a block of
Statements code if a condition is true and another block of code
if the condition is false.
End if
If the Boolean expression is false, the if statement
might be followed by an optional else statement.
The syntax of the if else statement is as follows:
If condition then If Else if Else statement
Statements The if else if else statement is used to execute a
block of code if a condition is true and another
Else
block of code if the condition is false.
Statements
First the program checks the first expression of the
End if program and if the requirement is false, it sends you
back to the if else condition.
If the Boolean expression is false, the if statement
Example:
might be followed by else statement.
If a>10 then In simple words, it will simply check the first
Print a expression and if the first expression is an error it
moves to the second.
Else
Print b
End if
And finally, need to end the statement using end if. example:
The syntax of the if else if else statement is as if a>10then
follows;
print a
If condition then
else if a<10 then
Statements
print b
Else if condition then
else
statements
print c
else
end if
statements
end if
SELECT CASE STATEMENT Select case expression
The test expression is evaluated by SELECT CASE, Case 1stexpression
which then performs the first matching CASE or
Statement A
CASE ELSE block and leaves.
Case 2ndexpression
The SELECT CASE statement is used to select one
of many blocks of code to be executed. Statement B
SELECT EVERY CASE allows all matching CASE Case Else
blocks or the CASE ELSE block to be executed in
Default expression
order from top to bottom.
Example;
LOOP
A loop is a set of instructions that is repeated until a
certain result is achieved.
Loops are used to run a group of instructions
repeatedly until a certain condition is satisfied.
FOR NEXT LOOP next variable
The for next loop is used to execute a block of code example;
for a specific number of times.
for I = 1 to 10 step 1
When you know precisely how many times you
print i
need to run the loop, its usually utilized as a counter
loop. next i
The syntax of the for next loop is as follows; this will print the numbers from 1 to 10
For variable = start to end step
statements