Lec-2 Introduction To Qbasic
Lec-2 Introduction To Qbasic
INTRODUCTION TO QBASIC
❑ Data Types
❑ Variables
❑ CLS Command
❑ INPUT Statement
❑ PRINT Statement
❑ END Command
2
Introduction to QBasic Interface
3
Introduction to QBasic Interface
4
Introduction to QBasic Interface
2. Menu Bar
The menu provides most of the operations for
the QBasic editor. Such as opening a file,
pasting text, and searching for a string.
5
Introduction to QBasic Interface
File Menu
New - Clears the current program
6
Introduction to QBasic Interface
Edit Menu
Cut - Removes the selected text and
stores it in the clipboard
Paste - Adds the text in the clipboard to the current position of the
cursor
7
Introduction to QBasic Interface
View Menu
SUBs - Shows the list of current
subroutines and functions
8
Introduction to QBasic Interface
Search Menu
Find - Allows 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
Run Menu
Start - Executes the current program
Restart - Starts from the beginning
Continue - Continues execution at the
current position
9
Introduction to QBasic Interface
Debug Menu
Step - Processes the next
command
Procedure Step - Processes the
next command, but 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. Use this to have the
QBasic interpreter stop when it reaches a specified line in the program
Clear All Breakpoints - Removes all breakpoints in the program
Set Next Statement - Allows you to continue execution at the specified line
10
Introduction to QBasic Interface
Options Menu
Syntax Checking - Allows you to have the QBasic editor check the syntax of
your program as you type
11
Introduction to QBasic Interface
Help Menu
Index - List of all QBasic commands,
keywords, operators, etc.
Contents - The table of contents for
QBasic help
12
Introduction to QBasic Interface
13
Introduction to QBasic Interface
5. Status bar
The status bar is at the bottom of the screen. It
displays a short list commands
<Shift+F1=Help> <F6=Window>
<F2=Subs> <F5=Run>
<F8=Step>
14
Introduction to QBasic Interface
15
Introduction to QBasic Interface
7. Current line
On the right side of the status bar, the current
line of the cursor is displayed.
8. Current column
On the right side of the status bar, the current
column of the cursor is displayed (immediately
after the current line).
16
DATA TYPES
18
VARIABLES
• Variables are names used to represent values
that are used in BASIC Program.
• There are two types: Numeric and String
• A numeric variable has a value that is a number.
• A string variable may have a single character or
many characters in it.
• A variable is a name that refers to an object--a
particular number, string, or record. (A record is
a variable declared to be a user-defined type.)
19
Variable NAMES
20
Variable NAMES
• A variable name cannot be a reserved word, but
embedded reserved words are allowed.
• For example, Log = 8 is illegal because LOG is a
reserved word [BASIC is not case sensitive, i.e.
Sales, SALES and sales all refer to the same
variable]
• However, the following statement is legal;
TimeLog = 8
• Reserved words include all BASIC commands,
statements, function names, and operator
names.
21
VARIABLE DECLARATION
22
AS declaration TYPE
23
AS declaration TYPE (contd.)
26
Type-declaration suffix (contd.)
27
Type-declaration suffix (contd.)
Examples
A% is integer type name
A$ is string type name
A& is long integer type name
A! or A is single-precision type name
A# is double-precision type name
28
CLS Command
29
INPUT Statement
A device I/O statement that reads input from the keyboard
during program execution and stores it into a list of variables.
Syntax:
INPUT[;][“PromptString”{;¦,}]VariableList
Argument Description
A semicolon immediately after INPUT keeps the cursor
;
on the same line after the user presses ENTER.
PromptString A string constant printed before the prompt character.
; Prints a question mark at the end of the PromptString.
, Prints the PromptString without a question mark.
A list of variables, separated by commas, to accept the
VariableList
input values.
30
INPUT Statement (contd.)
31
PRINT Statement
Syntax:
PRINT [expressionlist][{,¦;}]
32
END Command
Syntax: END
33
END
34