QBASIC
QBASIC
Dhapasi, Kathmandu
1
Acknowledgements
First and foremost, I would like to thank our Computer Science Teacher, Mr. Keshab Sir, for doing us
the courtesy of giving us a short, yet, considerate and feasible project work on the documentation of the
programming language—QBASIC; which stands for 'Quick Beginners’ All Purpose Symbolic Instruction
Code. Do keep in mind that this short documentation will unfortunately not cover the very basics of
QBASIC.
This short documentation of QBASIC incorporates its various facets such as its syntaxes, format, and
even examples, including over 50 QBASIC programs! I really do hope that you, the viewer, might be
able to fully assimilate the knowledge of QBASIC from this short documentation.
Special thanks to my friends, Kripesh, for the aptly font submissions; my friend, Subham, for planning
out this very acknowledgement page, alongside the introduction; and I would also like to thank my
friend, Raghav, for citing out all the references from both the internet and his own prior expertise in the
field.
I have also used our computer book, from Guinness Publication Pvt. Ltd. Pertaining to matters relating
to the contents of QBASIC. You need not to worry as it is contemporarily one of the computer books
approved by the Curriculum Development Centre (CDE) of Nepal. Computer-Zone book-9 is one of
Series on Computer Science designed for all the categories of student of Nepal. The book 9 of this series
is recommended for use in class 9.
Now that the above agendas for this documentation have been listed, it might be appropriate to just go
on with the rest of the document; but, before that, I would like to preface the specifications of this Word
Document if you have not noticed it yet:
1. Heading-font size: 16
2. Body-font size: 12
3. Header-font: Zapfino.
4. Body-font: Baskerville.
5. Number of words in the document: 4470
Nevertheless, I would like to reiterate my gratitude for this project work to my teacher, Mr. Keshab Sir,
for assigning this project work to us; and my peers for facilitating on the development of this work as I
did with theirs, kudos compadres!
Continuing forward…
2
Table of Contents
of Nepal Currently.
present in QBASIC
ion is true.
3
Introduction to QBASIC
The programming language BASIC (Beginners’ All Purpose Basic Instruction Code) as one of the
easiest programming languages which used English-words and mathematical notation as syntax for its
convenience. It was developed by Professors John Kemeny and Thomas Kurtz who had developed this
language in hopes of enticing students from non-scientific fields to use computers as writing code for
computers back then was very counter-intuitive and only exclusive to scientists and mathematicians.
In the emergence of microcomputers in the mid-1970’s led to the development of multiple dialects of
BASIC, including QBASIC in 1991 AD. QBASIC is a high-level programming language published by
Microsoft. The QBASIC environment or IDE (Integrated Development Environment) provides many
conveniences such as syntax checking, multi-file and multi-window editing, full debugging facilities,
pull-down menus, syntax-checking editor and a simple, yet, powerful menu structure that can be driven
through either by a keyboard or a mouse.
During the home computer craze in the late 1970’s and 80’s, BASIC was ported and supplied with
many home computer designs, alongside slight variations to add support for machine-specific functions.
As the early home computers gave away to newer designs like the IBM Personal Computer and Apple
Macintosh, it rendered BASIC to be redundant. In the end, we were left with the creation of QBASIC
in 1991 AD.
QBASIC is supposed to be MS-DOS exclusive which explains the DOS-like interface in the QBASIC
IDE. QBASIC had, for the time, a state-of-the-art IDE with debuggers, syntax-highlighting, etc.
QBASIC came complete with four pre-written example programs. These were Nibbles, a variant of
Snake game; Gorillas, an artillery game; Money Manager, a personal finance manager.
In spite of the promising possibilities that QBASIC provides us with, it has been rendered obsolete and
redundant due to many competitions amongst other programming languages such as SQL, Python, JS,
Java, C#, C++, Ruby, Swift, etc. Furthermore, QBASIC is exclusive to DOS only, so it isn’t very
versatile and all efforts to port it to other systems have failed; plus, languages like Python have far
simpler syntax, readability, debuggers, etc. and it has been outperformed in every aspect, even syntax-
highlighting!
Nevertheless, though QBASIC has been rendered obsolete and redundant in the modern 21st century
era, it has still been bestowed the honor of being included in many schools’ educational curriculum. It is
now used for education purposes; it has guided over many students and educators alike to be inured with
the world of computers; and to top it all off: QBASIC has raised a generation of people, like me, to be
well-acquainted with computers and truly assimilate the wonders and beautiful, yet complex, enigmas of
this world.
Continuing Forward
4
Elements of QBASIC
Variables:
Variable are the storage locations in the computer’s memory for storing data. It is referred to by a
name and whose value can be altered during program execution. The types of variables are:
i.) Numeric variable: A numeric variable has a number as its value. For e.g., d2 = 480
ii.) String variable: A string variable represents numbers, alphabets, and special characters. E.g. N$=”Dog”
Constants:
Constant is a vale stored in a program which does not change during program execution. It is classified into
the following types:
i.) Numeric constant: A numeric constant is a numeric value in which arithmetic operations are performed.
ii.) String constant: A string constant is a set of alphanumeric or special characters enclosed in double quotes.
An operator is a symbol representing the operations they perform on operands in a program. Operands are
the values on which the operators work on. The types of operators are:
i.) Arithmetic operators: +, -, /, \, MOD, *, ^
ii.) Relational operators: =, <, >, <=, >=, <>
iii.) Logical operators: AND, OR, NOT,
iv.) Concatenation operators: “comp” + “uter”
Keywords:
Keywords are the words that convey a special meaning to the language. These are reserved for special
purpose and just not be used as normal identifier names. Some of the QBASIC keywords are: REM, CLS,
INPUT, PRINT, and END.
5
QBASIC Operators’ Examples
Arithmetic Operators:
Relational Operators:
6
Logical Operators:
are true.
expression true.
Concatenation Operator:
An expression involving string variables and constants is called string expression. Concatenation operators
connect multiple strings into a single string. QBASIC uses the plus sign (+) as a string concatenation operator.
CLS
A$ = “Math Majors”
B$ = “Were Created”
C$ = “To Destroy”
D$ = “English Majors”
E$ = A$ + B$ + C$ + D$
Print E$
END
String comparisons are actually made by taking one character at a time from each string and comparing
their ASCII code values. If the ASCII codes in each string are the same, the strings are equal. If the
ASCII code in each string is different, t string with the lower code is less than the string with the higher code.
7
QBASIC Keywords
Introduction to Keywords:
Keywords are the words that convey a special meaning to the language. These are reserved for special purpose;
And must not be used as normal identifier names. Some of the QBASIC keywords are:
REM Statement:
REM Statement is used to include explanatory remarks to be inserted in a program which are very useful to
Explain what a group of statements achieve and what a variable stands for. Its syntax is:
REM <remark> or ‘<remark>’
CLS Statement:
CLS Statement is used to clear the output screen. It makes the screen completely blank. This command is
generally given before the start of any program so that there is a fresh screen and any left over from the
previous program is cleared completely. The general format of CLS is simply: CLS
LET Statement:
LET Statement is an assignment statement. It is used to assign the value of an expression to a variable. LET
is merely an optional keyword i.e., the equal sign is sufficient when assigning an expression to a variable name.
The type of the expression must be the same as the type of the variable. The general syntax of LET is:
LET <variable> = <expression>
INPUT Statement:
Input Statement is used to accept input from the keyboard during the execution of the program. It facilitates
the use of same program for various sets of data to obtain different results in different executions. Syntax:
INPUT [”definer”;|]list of variables
READ…DATA Statement:
READ Statement is used to read values from DATA statement and assign them to variables. Syntax:
READ [variable1, variable2, …]
…
DATA [constant1, constant2, …
PRINT Statement:
Print statement is used to display data on the screen. This statement will print constants, variables, expressions, etc.
Syntax: PRINT [list of expressions] [, \ ;] or ? [list of expressions] [, \ ;]
8
QBASIC Branching Statements
GOTO Statement:
GOTO Statement is used for unconditional transfer of execution from one part of the program to the other. It does
not depend on any test of condition. The general format of GOTO statement is:
GOTO [line number | line label]
IF…ELSEIF…ENDIF Statement :
IF…ELSEIF…ENDIF statement is another variation of IF…THEN…ELSE statement. You can have an indefinite
number of ELSEIF clauses. The conditions are evaluated from top to bottom. As soon as one of the conditions
controlling IF is true, the statement associated with that IF is executed; and if none is true, then it will return to
ELSE which is the default statement. Syntax:
IF [condition1] THEN
[statementblock-1]
ELSEIF [condition2] THEN
[statementblock-2]
ELSE
[statementblock-3]
END IF
ON…GOTO Statement :
ON…GOTO Statement is a conditional statement on QBASIC which provides multiple branching facilities to a
program. When an expression is met, it redirects the flow of the program to a certain line. Syntax:
ON expression GOTO line1 [, line2]…
SELECT…CASE Statement :
Select…Case statement is a multi-branch selection statement that makes the control jump from one of the several
statements based on the value of an expression. If the values of the test expression correspond with the value or
values in the CASE statement, the commands after the CASE statement are executed. If the value does not match,
the CASE goes on to the next CASE statement. The general format of the SELECT…CASE statement is:
SELECT CASE test exp
CASE test1
Statements
CASE test2
Statements
…
CASE ELSE
Statements
END SELECTs
Continuing Forward…
9
QBASIC Looping Statements
Preface: A looping statement allows a set of instructions to be repeated a certain number of times. The repetition
continues while the condition set for it remains true. When the condition becomes false, the loop ends and the
control is passed to the statement, following the loop. The looping statement is also called an iterative statement.
QBASIC supports the following looping statements:
FOR…NEXT Statement :
FOR…NEXT statement is a count-controlled loop. It is used to execute a series of instructions a given number
of time. The general format of FOR…NEXT statement is:
FOR <counter variable> = x to y <STEP z>
<program statements>
EXIT <counter variable>
WHILE…WEND Statement :
WHILE…WEND statement is an entry-controlled loop. It is used to execute a series of statements as long as a
given condition is true. If the condition is true, all the statements are executed and when the WEND statement is
reached, control is returned to the WHILE statement. The general format of WHILE…WEND statement is:
WHILE <condition>
<program statements>
WEND
DO…LOOP Statement :
DO…LOOP statement causes a set of program statements to execute repeatedly until certain conditions are met
or as long as certain conditions are true. There are two variations of DO…LOOP statement and both use the same
basic model. A loop can execute either while the conditions are true or until the conditions becomes true. These
two variations use the keywords WHILE and UNTIL to specify how long the statements are executed. The syntax
for DO…LOOP statement can take either of the two forms:
DO
<statement block>
LOOP WHILE\Until <boolean expression>
OR
Continuing Forward…
10
QBASIC Sample Programs
CLS
REM “WAP to find area of rectangle.”
INPUT “Enter the length”; l
INPUT “Enter the breadth”; b
A = l*b
PRINT “Area of Rectangle is”; A
END
CLS
REM “WAP to find perimeter of square”
INPUT “Enter the length”; l
P = 4*l
PRINT “Perimeter of square is”; P
END
CLS
REM “WAP to find area of right-angled triangle”
INPUT “Enter the length”; l
INPUT “Enter the breadth”; b
a = (1/2)*l*b
PRINT “Area of right-angled triangle is”; a
END
CLS
REM “WAP to print your name 10 times.”
INPUT “Enter your name:”; N$
FOR I = 1 to 10
PRINT N$
NEXT I
END
CLS
REM “WAP to find area of circle”
CONST pi = 3.141
INPUT “Enter the Radius”; R
A = pi*R^2
PRINT “Area of circle is”; A
END
11
CLS
REM “WAP to find first 10 odd numbers”
FOR I = 3 to 10 STEP 2
PRINT I
NEXT I
END
CLS
REM “WAP to find greatest among two numbers”
INPUT “Enter the P”; P
INPUT “Enter the T”; T
IF P > T THEN PRINT “P is greater”
ELSE PRINT “T is greater”
END
CLS
REM “WAP to find to find sum of two values, a and b”
INPUT “Enter the a”; a
INPUT “Enter the b”; b
c = a + b
PRINT “The sum of the two values is”; c
END
CLS
REM “WAP to find area of square”
INPUT “Enter the l”; l
A = l^2
PRINT “Area of square is”; A
END
CLS
REM “WAP to find print first 10 multiples of 2”
FOR I = 1 to 10
PRINT 2*I
NEXT I
END
CLS
REM “WAP to find print first 50 multiples of 5”
FOR I = 1 to 50
PRINT 5*I
NEXT I
END
12
CLS
REM “WAP to find profit”
INPUT “Enter the cost price”; cp
INPUT ‘Enter the selling price”; sp
Profit = sp – cp
PRINT “Profit made is”; Profit
END
CLS
REM “WAP to find sum of individual digits”
INPUT “Enter a number”; N
WHILE N <> 0
R = N MOD 10
S = S + R
N = N\10
WEND
PRINT “Sum of individual digits is”; S
END
CLS
REM “WAP to find product of individual digits”
S = 1
INPUT “Enter a number”; N
WHILE N <> 0
R = N MOD 10
S = S*R
N = N\10
WEND
PRINT “Product of individual digits is”; S
END
CLS
REM “WAP to find reverse of individual digits”
INPUT “Enter a number”; N
WHILE N <> 0
R = N MOD 10
S = S*10+R
N = N\10
WEND
PRINT “Reverse of individual digits is”; S
END
13
CLS
REM “WAP to find the sum of first 10 natural numbers”
FOR I = 1 to 10
SUM = SUM + I
NEXT I
PRINT “The sum of first 10 natural numbers is:”; SUM
END
CLS
REM “WAP to input a number and check if it is an Armstrong number or not.”
INPUT “Enter N’; N
J = N
WHILE J <> 0
R = J MOD 10
S = S + R^3
J = J\10
WEND
IF N = S THEN PRINT “It is an Armstrong number”
ELSE PRINT “IT is not an Armstrong number.”
END
“
CLS
REM “WAP to return NEP from NEPAL”
N$ = “NEPAL”
PRINT LEFT$(N$,3)
END
CLS
REM “WAP to check whether a number is divisible by both 5 and 3”
INPUT “Enter N”; N
IF (N/5=0) and (N/3=0) THEN
PRINT “It is divisible by 5 and 3”
ELSE
PRINT “It is not divisible by 5 and 3”
END IF
END
CLS
REM “WAP to return MAN from KATHMANDU”
N$ = “KATHMANDU”
PRINT MID$(N$,5,3)
END
14
CLS
REM “WAP to enter a number and find its half”
INPUT “Enter a”; a
B = a/2
PRINT “Half of the number given is”; B
END
CLS
REM “WAP to find the speed of an object”
INPUT “Enter the distance covered”; d
INPUT “Enter the time taken”; t
S = d/t
PRINT “The speed of the object is”; S
END
CLS
REM “WAP to find the acceleration of an object”
INPUT “Enter the initial velocity”; i
INPUT “Enter the final velocity”; v
INPUT “Enter the time taken”; t
A = (v-i)/2
PRINT “The acceleration of the object is”; A
END
CLS
REM “WAP to find the force of an object”
INPUT “Enter the mass”; m
INPUT “Enter the acceleration”; a
F = m*a
PRINT “The force of the object is”; F
END
CLS
REM “WAP to find the percentage”
INPUT “Enter the obtained marks”; m
INPUT “Enter the total marks”; t
P = (m/t)*100
PRINT “The percentage is”; P
END
15
CLS
REM “WAP to find volume of cuboid”
INPUT “Enter the length”; l
INPUT “Enter the breadth”; b
INPUT “Enter the height”; h
V = l*b*h
PRINT “Volume of cuboid is”; V
END
CLS
REM “WAP to find volume of cube”
INPUT “Enter the length”; l
V = l^3
PRINT “Volume of cube is”; V
END
CLS
REM “WAP to find volume of cylinder”
CONST pi = 3.141
INPUT “Enter the radius”; r
INPUT “Enter the height”; h
V = pi*r^2*h
PRINT “Volume of cylinder is”; V
END
CLS
REM “WAP to convert kilogram to pounds”
INPUT “Enter your weight in kilograms”; k
P = k*2.2
PRINT “Your weight in pounds is”; P
END
CLS
REM “WAP to find area of four walls”
INPUT “Enter the length”; l
INPUT “Enter the breadth”; b
INPUT “Enter the height”; h
A = 2*h*(l+b)
PRINT “The area of four walls is”; A
END
16
CLS
REM “WAP to find if the given number is even or odd.”
INPUT “Enter a”; a
IF a MOD 2 = 0 THEN
PRINT “It is an even number”
ELSE
PRINT “It is an odd number”
END IF
END
CLS
REM “WAP to find the greatest among three numbers”
INPUT “Enter a”; a
INPUT “Enter b”; b
INPUT “Enter c”; c
IF (a > b) and (a > c) THEN
PRINT “A is greatest”
ELSE IF (b > a) and (b > c) THEN
PRINT “B is greatest”
ELSE
PRINT “C is greatest”
END IF
END
CLS
REM “WAP to find product of three numbers”
INPUT “Enter a”; a
INPUT “Enter b”; b
INPUT “Enter c”; c
Sum = a * b * c
PRINT “The product of three numbers is”; Sum
END
CLS
REM “WAP to find the average of three numbers”
INPUT “Enter a”; a
INPUT “Enter b”; b
INPUT “Enter c”; c
Average = (a+b+c)/3
PRINT “Average of the three numbers is”; Average
END
17
CLS
REM “WAP to reverse any the string COMPUTER”
C$ = “COMPUTER”
FOR I = 8 to 1 STEP -1
M$ = MID$(C$,J,1)
REV$ = REV$ + M$
NEXT J
PRINT “Reversed string of COMPUTER is”; REV$
END
CLS
REM “WAP to enter your name, age and grade; and print them.”
INPUT “Enter your name”; n$
INPUT “Enter your age”; a$
INPUT “Enter your grade”; g$
PRINT “Your name is”; n$
PRINT “Your age is”; a$
PRINT “Your grade is”; g$
END
CLS
REM “WAP to print the following: 7 77 777 7777 77777”
CLS
A = 7
FOR I = 1 to 5
PRINT a;
A = A*10+7
NEXT I
END
CLS
REM “WAP to enter two numbers and find their quotient and remainder”
INPUT “Enter a”; a
INPUT “Enter b”; b
q = a\b
r = a MOD b
PRINT “The quotient is”; q
PRINT “The remainder is”; r
END
18
CLS
REM “WAP to find the perimeter of a rectangle”
INPUT “Enter the length”; l
INPUT “Enter the breadth”; b
P = 2*(l+b)
PRINT “Your weight in pounds is”; P
END
CLS
REM “WAP to convert kilometers into miles”
INPUT “Enter the length in kilometers”; k
M = k/1.6
PRINT “The length in miles is”; M
END
CLS
REM “WAP to convert NPR to INR”
INPUT “Enter NPR”; N
I = N*1.6
PRINT “Indian currency is”; I
END
CLS
REM “WAP to convert IPR to NNR”
INPUT “Enter IPR”; I
N = I/1.6
PRINT “Nepalese currency is”; N
END
CLS
REM “WAP to see if it is a positive or negative number”
INPUT “Enter a number”; N
IF N > 0 THEN PRINT “It is a positive number.”
ELSE PRINT “It is a negative number.”
END
CLS
REM “WAP to find sum of three numbers”
INPUT “Enter a”; a
INPUT “Enter b”; b
INPUT “Enter c”; c
S = a + b + c
PRINT “Sum of three numbers is”; S
END
19
CLS
REM “WAP to find SI and Amount”
INPUT “Enter the Principal”; P
INPUT “Enter the Time”; T
INPUT “Enter the Rate”; R
SI = (P*T*R)/100
A = SI+P
PRINT “SIMPLE INTEREST IS”; SI
PRINT “Amount is”; A
END
CLS
REM “WAP to find circumference of a circle”
CONST pi = 3.141
INPUT “Enter the radius”; r
A = 2*pi*r
PRINT “Circumference of circle is:”; A
END
CLS
REM “WAP to print first ten natural numbers”
N = 1
WHILE N <= 10
PRINT N
N = N+1
WEND
END
CLS
REM “WAP to find even numbers from 1 to 10”
FOR I = 1 to 10 STEP 2
PRINT I
NEXT I
END
CLS
REM “WAP to find squares of even numbers from 1 to 10”
FOR I = 1 to 10 STEP 2
PRINT I^2
NEXT I
END
20
CLS
REM “WAP to enter your name and marks in 3 subjects, then find the
division and print the division and name.”
INPUT “Name:”; N$
INPUT “Marks in Math”; m
INPUT “Marks in Computer”; c
INPUT “Marks in Science”; s
T = m+c+s
P = (T/300)*100
IF P > 60 THEN
PRINT “Name:”; N$
PRINT “First divison”
ELSE IF (P >= 45) and (P <= 60) THEN
PRINT “Name:”; N$
PRINT “Second divison”
ELSE IF (P >= 32) and (P <= 44) THEN
PRINT “Name:”; N$
PRINT “Third division”
ELSE IF (P < 32) THEN
PRINT “Name:”; N$
PRINT “Failed”
END IF
END
Continuing Forward…
21
Conclusion and Citations
In conclusion of all the aforementioned contents of this short documentation, we can find it evident that
QBASIC is, indeed, a beginner-friendly, easy-to-grasp, and fun programming language with unique, easy
syntaxes which introduced a whole generation of people to program development in the technical
scale. It has its perks even for non-computer enthusiasts; nowadays, schools have introduced QBASIC
into its curriculum which has proved beneficial for children to develop their cognitive reasoning skills,
spatial reasoning skills, language skills, arithmetic skills, and, overall, has been able to equip children with
the skills needed to function in everyday society.
When I was preparing this short documentation of QBASIC I got as an assignment, I honestly had a great
time and felt this overwhelming sense of gratitude towards book publishers who overlook the entire design,
contents, and overall viewer-engagement of the books that they publish. Seeing everyone just completely
undermining the value of these books for very saddening to see. Nonetheless, I will cherish this week-whole
process of I, Nischal Tulachan, trying to perfect this small document which might not be the grandest of
goals but, in my mind, is irreplaceable. Many years hence, I would like to reminisce about my time in school
and the bonds I have made; and in that moment, I would want this document to be a memento of my time
in school. Thank you for coming to my Ted Talk!
Citations:
1. "Differences Between GW-BASIC and QBasic". 2003-05-12. Archived from the original on 2008-02-21.
2. "QBASIC Manual: SUB...END SUB Statement QuickSCREEN". Archived from the original on 2008-10-7.
3. "QBASIC Manual: TYPE Statement QuickSCREEN". Archived from the original on 2017-03-24.
4. "QBASIC Manual: Limits - Names, Strings, and Numbers". Archived from the original on 2016-03-04.
5. "Microsoft BASIC version information". Retrieved 2008-06-12.
6. "QBasic Missing from Windows 2000". 2007-03-01.
7. "QBasic - Developer Credits". 1999-07-23. Retrieved 2008-06-12.
8. “BASIC – A Wikipedia Article”. Sourced from Wikipedia.
THE END
22