This document provides an introduction to QBASIC programming. It outlines the key elements of QBASIC including its features, character sets, keywords, variables, constants, operators, expressions, and statements. It discusses the different types of variables like numeric, string, and constant variables. The document also explains arithmetic, relational, and logical operators. Overall, the document serves as a high-level overview of the basics of QBASIC programming.
Seal of Good Local Governance (SGLG) 2024Final.pptx
Basic of qbasic
1. Hello! & Namaste
I am Roshan Maharjan
I am here because I love to give
presentations.
You can find me at
@https://slideshare.net/RoshanMaharjan13
@fsscomputer2020@gmail.com
1
3. OUTLINES
➢ Identify the special features of QBASIC.
➢ Explain the elements of QBASIC programming.
➢ Identify the various methods of declaring
variables.
➢ Explain the importance of QBASIC syntax.
3
4. “Our greatest weakness lies in giving up.
The most certain way to succeed is
always to try just one more time.” –
Thomas A. Edison
4
6. Introduction
▪ QBasic is a simple programming language developed by
Microsoft to type, edit, debug and execute BASIC programs.
▪ A QBasic program consists of various elements. They are
a character set, constants, variables, statements, operators
and expressions.
▪ A QBasic statement is a command or set of instructions to
perform a certain task.
▪ BASIC is an interpreter which means it reads every line,
translate it and lets the computer execute it before reading
another.
▪ Each instruction starts with a line number.
6
7. Features
▪ It is simple and easy to learn.
▪ It is an interpreter having its own editor.
▪ It has dynamic program debugging
▪ It supports the local and global variable.
▪ It supports modular programming.
▪ It capitalizes the reserved words automatically.
▪ The syntaxes of the statements are checked automatically
7
9. Starting QBASIC
▪ QBASIC may not be on your computer.
▪ At first, you need to have QBASIC in your computer.
▪ It is freely available. You can download it from the
Internet as well..
QBASIC Interface
9
10. Components of Qbasic
Menu Bar
It Consists of a
list of menus
like file, edit,
view, search,
Run, options
and help.
Program Window
The upper window
tittles “untitled” is
the window where
you write the
complete program.
F5 key is pressed to
execute or run the
program to get the
result.
Immediate Window
The lower window is
titled immediate
window where the
simple statements are
typed which get
executed immediately.
Errors are displayed
here.
10
Status Bar
It shows
shortcut keys
and location
of the cursor
on the screen.
11. File Menu Options
11
File Menu
New Clears the current program.
Open Loads a program from the desk.
Save Saves the current program to disk.
Save As
Saves the program, but under a different
name.
Print
Prints the selected text, current window,
or entire program.
Exit Closes the QBASIC interpreter.
12. Edit Menu Options
12
Edit Menu
Cut
Removes the selected text and stores it in the
clipboard.
Copy
Copies the selected text instead of removing
it.
Paste
Adds the text in the clipboard to the current
position of the cursor.
Clear
Removes the text without storing it on the
clipboard.
New Sub Enables you to create a new subroutine
New Function Enables you to create a new function
13. View Menu Options
13
View Menu
SUBs
Shows the list of current subroutines and
functions.
Split
Displays the contents of the current program
in two windows. If the window is already split,
this hides the second window.
Output
Screen
Shows the Qbasic output screen
14. Search Menu Options
14
Search Menu
Find
Allow you to search for a string of text in
the program
Repeat Last
Find
Continues the previous search operation
Change
Replaces each instance of a string with
another string
15. Run Menu Options
15
Run Menu
Start
Allow you to search for a string of text in the
program
Restart Continues the previous search operation
Continue
Replaces each instance of a string with
another string
16. Debug Menu Options
16
Debug Menu
Step Processes the next command
Procedure
Step
Processes the next command, does not show
Qbasic going inside a subroutine or function.
Trace On
Shows the command that is being executed
while the program is running.
Toggle
Breakpoint
Sets or removes a breakpoint.
Set Next
Statement
Allows you to continue execution at the
special line
17. Help Menu Options
17
Help Menu
Index
To display the help index by listing all the
commands, keywords, operators, etc
Contents To display the help table of content
Topic
To display information on a topic determined
by the current location of the cursor.
Using Help Displays information on using QBASIC help.
About
Shows information about the QBASIC
interpreter
18. ▪ Character Sets
▪ Keywords
▪ Variable
▪ Constants
▪ Operators, expressions and operand
▪ Program statements
18
Elements of QBASIC
19. Character set is a set of valid characters that a language can
recognize.
A character represents any letter, digit, or any other sign.
The QBASIC has the following character sets:
▪ Alphabets A, B.. Z, a, b, c,.....z.
▪ Number 0-9.
▪ Special symbols like ;,=, +,-,/,*,( ),%, $, #, &, ?,<, >etc.
Character Set
19
20. ▪ 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, CLS, INPUT,
LET, PRINT and END
Keywords
(Reserved Words)
20
🔑
21. Variable
21
▪ Variables are the memory locations in the computer’s
memory for storing data.
▪ They provide an “interface” to RAM.
▪ They are the containers that holds the information.
▪ Their sole purpose is to label and store the data in
memory so that can be used throughout the program.
22. The variable names have the following properties:
22
Continue……
Variable - Naming Conventions
▪ Any Variable name may be up to 40 characters long.
▪ Variable names must begin with a letter ( A…Z, a…z ).
▪ Cannot contain characters other than letters, numbers, period, and the type declaration
characters ($, %, #, &, and ! ).
▪ Cannot be a reserved words, although embedded reserved words are allowed.
▪ Variable may represent either numeric values or string.
▪ Cannot begin with “FN” unless it is a function call.
23. Variables occur in two distinct types i.e. numeric variable and string variable depending
upon data item they represent.
23
Continue……
Types of variables
▪ Numeric Variable
• Numeric variables store numeric data.
• It’s name can be formed by letters and digits.
• It should however always begin with an alphabet and should not contain any
special characters or spaces.
• For example, (i) age = 30 (ii) mark1 = 73.6. Here age is a numeric variable which
stores the constant value 30.
• Numeric variables may be declared as:
24. 24
Continue……
Numeric Variable
▪ Integers
• Integer variable is declared by using a percent sign (%) as the last character of the
variable name
• They are stored as 2 bytes ranging in value from -32768 to +32767.
• The declaration of a variable as an integer causes the variable’s value to be rounded
to the closest integer.
• For example: A% = 50
• They accept only non-decimal values i.e real values
25. 25
Continue……
Numeric Variable
▪ Long Integers
• Long Integer variable is declared by using a ampersand sign (&) as the last
character of the variable name.
• They are stored as 4 bytes ranging in value from -2,147,483,648 to + 2,147,483,648
• For example: A& = 5023456
26. 26
Continue……
Numeric Variable
▪ Single Precision
• Single Precision variable is declared by using a exclamation sign (!) as the last
character of the variable name
• They are stored as 2 bytes ranging in value from -3.37 x 10^38 to + 3.3 x 10^38.
• The declaration of a variable as single precision and exceeds seven digits is rounded
to its closest value.
• Although the seventh digit is displayed, its accuracy is not dependable.
• For example: A! = 123.4567
27. 27
Continue……
Numeric Variable
▪ Double Precision
• Double Precision variable is declared by using a Hash sign (#) as the last character of
the variable name
• They are stored as 4 bytes ranging in value from -1.67 x 10^308 to + 1.67 x 10^308.
• The declaration of a variable as double precision and exceeds 16 digits is rounded to
its closest value.
• For example: Count# = 123.4567
28. 28
String Variable
▪ String variables represents numbers, alphabets, and special characters.
▪ This variable should:
• begin with an alphabet.
• end with dollar sign($).
• be of more than one characters and numbers but no special characters
are allowed
▪ Data are stored inside double quotation.
▪ Example: A$ = “Hello world”
29. 29
Constant
▪ Constant is a value stored in a program which does not change during program
execution.
▪ Based on the type of data, it is classified into two types:
• Numeric Constant
• Numeric constant is a numeric value on which mathematical operations
such as addition, subtraction, multiplication and division can be
performed.
• It consists of sequence of digits (0-9) with or without decimal point.
• It can be a positive or negative numbers.
• Example: 17, -54, 23.5, -7.5.
30. 30
Continue……
Constant
• String constant is a set of alphanumeric or special characters enclosed within
double quotes.
• Blank spaces can also be used in a string.
• These type of data cannot be used for mathematical calculations but can be used for
comparisons and references.
• For example: “Computer Science”, “Fluorescent”
• String Constant
• Symbolic Constant
• Symbolic constant is used when a value is not expected to change during the
execution of the program.
• The CONST statement is a non-executable statement that declares symbolic
constants.
• For example: CONST PI = 22/7
31. 31
Operator and Expression
▪ An operator is a symbol representing the operations they perform on
operands in a program.
▪ The value on which the operators work are referred to as operands.
▪ An expression is a programming statements that has a value.
▪ It is composed of operators and operands.
▪ Operators perform mathematical or logical operations on values
▪ Types of Operators.
• Arithmetic operators.
• Relational operators.
• Logical operators.
• String operators.
32. Arithmetic operators
32
▪ Arithmetic operators performs arithmetic operations on the numeric
values or on the variables holding numeric values.
▪ An expression formed with arithmetic operators is termed as arithmetic
expressions.
Operators Operations Example Result
^ Exponential X = 2 ^3 X = 8
- Negation x = -y X = -(9-3) X = - 6
* Multiplication X = 3 *3 X = 9
/ Floating-point Division X = 5/2 X = 2.5
Integer Division X = 52 X = 2
MOD Modulus Division X = 5 MOD 2 X = 1
+ Addition X = 3 + 4 X = 7
- Subtraction X = 6 – 3 X = 3
33. Relational operators
33
▪ Relational operators are used to evaluate and compare two values of the
same type, either both numeric or both string.
▪ The result of comparison is either TRUE or FALSE.
Operators Operations Example Result
= Equal 6 = 5 False
< Less than 6<5 False
>
Greater than 6>5
5>6
True
False
<=
Less than or equal to 6<=5
5<=6
False
True
>=
Greater than or equal to 6>=5
5>=6
True
False
<> Not equal to 6<>5 True
34. Logical operators
34
▪ Logical operators are used to connect two or more relational expressions
to evaluate a single value as True or False.
▪ The logical operators supported by QBASIC are:
▪ AND operator
• When two logical expressions are combined using AND logical
operator, the entire logic operation will be TRUE only if both the
logical expressions are individually TRUE.
▪ OR operator
• The entire logic operation in this case will be TRUE if either of
the logical expression is TRUE.
▪ NOT operator
• Not is a negative check operator. It operates with one operand
• It is used to reverse the logical state of its operand. If a
condition is true, then Logical NOT operator will make it false.
35. Logical operators
35
▪ Truth Table
Value (A) Value (B) A AND B A OR B NOT A
F F F F T
F T F T T
T F F T F
T T T T F
36. 36
Concatenation Operator
▪ An expression involving string variables and constants is called string
expression.
▪ Concatenation operators connect multiple strings into a single string.
▪ QBASIC use the plus sign (+) as a string concatenation operator.
▪ QBASIC use the plus sign (+) as a string concatenation operator.