[go: up one dir, main page]

0% found this document useful (0 votes)
222 views34 pages

Lec-2 Introduction To Qbasic

This document provides an introduction to the QBasic programming interface. It describes the main components of the QBasic IDE, including the coding area, menu bar, status bar, and other interface elements. It also covers basic data types in QBasic like numeric, string, and user-defined types. Finally, it discusses variables, how to declare them, and valid naming conventions.

Uploaded by

Usman Akmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
222 views34 pages

Lec-2 Introduction To Qbasic

This document provides an introduction to the QBasic programming interface. It describes the main components of the QBasic IDE, including the coding area, menu bar, status bar, and other interface elements. It also covers basic data types in QBasic like numeric, string, and user-defined types. Finally, it discusses variables, how to declare them, and valid naming conventions.

Uploaded by

Usman Akmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

COMPUTER PROGRAMMING

INTRODUCTION TO QBASIC

DR. USMAN AKMAL


DR. ALI AHMAD

DEPARTMENT OF CIVIL ENGINEERING


UNIVERSITY OF ENGINEERING AND TECHNOLOGY,
LAHORE
CONTENTS
❑ Introduction to QBasic Interface

❑ 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

1. Current Program / Codding Area


The current program / codding area is
displayed in the middle of the screen, and
covers most of the 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

Open - Loads a program from disk

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

6
Introduction to QBasic Interface

Edit Menu
Cut - Removes the selected text and
stores it in the clipboard

Copy - Copies the 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 to the clipboard

New Sub - Enables you to create a new subroutine

New Function - Enables you to create a new function

7
Introduction to QBasic Interface

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
(NOTE: The text in each window is
always the same, even if you alter the
text in one window)

Output Screen - Shows the QBasic


output screen.

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

Display - Enables you to change


display colors, the number of
spaces to use for tabs, and
whether or not scroll bars are
visible

Help Path - The location of the QBASIC.HLP file

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

Topic - Show help for a specific


keyword

Using Help - Displays information on


using QBasic help

About - Shows information about the


QBasic editor

12
Introduction to QBasic Interface

3. Name of current program


The file name of the current program is
displayed near the top of the screen in the
center. You can change the name by selecting
"Save As" on the "File" menu.
4. Immediately execute a command
QBasic provides a way to execute a command
without running the current program. To do so,
select the bottom window (under "immediate")
and enter a command, then press Enter.

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>

When you highlight an item on the menu, the


status bar displays a short description of what
the item does.

14
Introduction to QBasic Interface

6. Status of Caps Lock and Num Lock


If Caps Lock is set, a "C" is displayed on the
right side of the status bar.

If Num Lock is set, a "N" is displayed on the


right side of the status bar.

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

DATA TYPES IN VB (QB)


BOOLEAN BYTE
CURRENCY DATE
INTEGER LONG
SINGLE DOUBLE
STRING OBJECT
USER DEFINED VARIANT
17
DATA TYPES (contd.)

Memory Range of Values


Data Type Size
(Bytes) +ve -ve
Integer 2 +32,767 -32,768

Long 4 +2,147,483,647 -2,147,483,648

3.402823 x 1038 -2.802597 x 10-45


Single 4 To To
2.802597 x 10-45 -3.402823 x 1038
1.79769313486231 x 10308 -4.940656458412465 x 10-324
Double 8 To To
4.940656458412465 x 10-324 -1.79769313486231 x 10308
String 2+LEN 32,767

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

• A BASIC variable name may contain up to 40


characters.
• The characters allowed in a variable name are
letters, numbers, the period (.), and the type-
declaration characters (%, &, !, #, and $).
• The first character in a variable name must be a
letter.
• A variable name can not contain space.

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

Simple variables can be numeric, string, or record


variables. You may specify simple variable types
in three different ways:
i. AS declaration statement
ii. Type-declaration suffix
iii. DEFtype declaration statement

22
AS declaration TYPE

Defining the variable in a declaration type has


the following form
declare variablename AS type
where the "declare" can be either DIM,
COMMON, REDIM (for arrays), SHARED, or
STATIC
and the "type" can be either INTEGER, LONG,
SINGLE, DOUBLE, STRING, or a user-defined
type.

23
AS declaration TYPE (contd.)

For example, the following statement declares


the variable a as having a long-integer type:
DIM a AS LONG
More Examples
DIM X AS SINGLE, Y AS DOUBLE
DIM Xy AS STRING, I AS Long, j AS Byte
DIM k AS single, kk AS single
DIM XYZ AS STRING*30
24
AS declaration TYPE (contd.)

String variables declared in an AS STRING


clause can be either variable-length strings or
fixed-length strings.
Variable-length strings are expandable: their
length depends on the length of any string
assigned to them.
Fixed-length strings have a constant length,
specified by adding “*number" to the AS
STRING clause, where number is the length of
the string in bytes.
25
Type-declaration suffix

Append one of the type-declaration suffixes to


the variable name as given in the following
Table.
Suffix Data Type
% Integer
& Long integer
! Single-precision
# Double-precision
$ String

26
Type-declaration suffix (contd.)

You can assign a string constant to the


variable of up to 32,767 characters, as in the
example below.
A$ = "SALES REPORT"

Single precision is the default for variables


without a type suffix.

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

When a program reaches a line containing


CLS, it erases the output screen. Following is
the syntax of this command;
Syntax: CLS

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.)

• The INPUT statement causes the program to


pause and wait for data. One may enter the
required data at the keyboard.
• The entered data is assigned to the variables in
variablelist.
• The number of data items that one supply must
be the same as the number and type of variables
in the list.

31
PRINT Statement

A device I/O statement that outputs data on the screen.

Syntax:
PRINT [expressionlist][{,¦;}]

• If expressionlist is omitted, a blank line is printed.


• If expressionlist is included, the values of the expressions
are printed on the screen.
• The expressions in the list may be numeric or string
expressions. (string literals must be enclosed in quotation
marks.)

32
END Command

• One may use END command to the end of Qbasic


programs.
• Although using END was required in earlier versions of
BASIC, this command is now optional.
• Some people always use and END statement to eliminate
any ambiguity on the part of readers as to whether they
have reached the true end of the program.

Syntax: END

33
END

34

You might also like