The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by Allstar Technology, 2020-06-04 03:08:52

New gateway computer 10press-2077 final

New gateway computer 10press-2077 final

Since, entire data are managed and kept in a table for the future retrieval process, it is also
called the primary object of database. The various elements of database are listed below.

Tables

A database table is composed of records and fields that hold data. Tables are also called
datasheets. Each table in a database holds data about a different, but related, subject.
Table stores a large volume of data into rows and column format as below. In the given
table, SN, Book_Name , Quantity and Rate are the field names and the information stored
on each field is called record.

SN Book_Name Quantity Rate
100
1 Computer Science 10 150
125
2 Social Studies 15 275
185
3 Moral Science 25

4 Optional Mathematics 28

5 Nepali 20

Records

Data are stored in records. A record is composed of fields and contains all the data about
one particular person, company, or item in a database. Records appear as rows in the
database table. A record for S.N. 5 is given as below from the above table.

SN Book Name Quantity Rate
185
5 Nepali 20

Fields

A field is part of a record and contains a single piece of data for the subject of the record. A
field or column contains information about a certain type for all records. In the given table
SN, Book_Name, Quantity and Rate are the fields of table where Book Name contains the
name of each book in the table.

Book Name
Computer Science
Social Studies
Moral Science
Optional Mathematics
Nepali

New Gateway to Computer Science Book -10 101

Value

Each specific piece of information in a table is known as value. For example, in the table
given below, Computer Science is a value in Book Name field and 10 is a value in the
Quantity field. Value is located at the cell of table which is also called the intersection of
row and column.

Quantity Rate
10 100

Relational Database Management System (RDBMS)

It is a collection of related data. It is defined as a method of viewing information for
several, separated database that relate one to another through keywords or values.
RDBMS are database management systems that maintain data records and indices in
tables. Relationships may be created and maintained across and among the data and
tables. MS-ACCESS and Oracle are the best examples of RDBMS software.

Introduction to Microsoft Access

Microsoft Access is a Relational Database Management System (RDBMS) that helps us
to store information for reference, reporting, and analysis. Access is known as a desktop
database system because it’s functions are intended to be run from a single computer. We
can use various ways to create a database by using MS-Access. Access was developed
by Microsoft Company. This software is distributed along with the Microsoft Office
application package. Microsoft Access 2010 is the latest version available in the market.

Features of Microsoft Access
 It provides very useful database features such as tables, forms, reports and queries.
 It works as front end development tool.
 It provides end-user applications developer environment.
 It shares data with other applications such as Microsoft Word or Excel.
 It support three computer programming languages such as: SQL, Macros and Visual
BASIC, etc.

Objects of MS-Access

Table: Table is a collection of various records. A table is a feature, comprising of parallel
columns and rows, which is used to store, organize, and view data on a particular topic. A

102 New Gateway to Computer Science Book -10

single database may contain numerous tables containing information about related topics,
such as customer addresses, product prices, and other information.

Form: A form is an object of database which shows only the information you want to see.
A form is used to view data in a database, enter new data into the database, or edit data.
We can create from in database by using Design View , Auto form tabular , Auto form
Columnar, Form Wizard, etc.

Report: A report is used to show and print selected information from a table in a
customized manner. A report differs from a form because it does not allow you to make
any modifications or edits to the actual records within the table or tables.

Query: A query is a question that you ask about the data in your table(s). Query is also
used to perform various mathematical calculation is the database records.

Let’s Review
 Database is an organized collection of related information or data.

 A database consists of a file or a set of files that can be broken down into records,
each of which consists of one or more fields.

 Data are raw, unorganized facts that need to be processed which have no meaning.

 A database management system (DBMS) is designed to manage a large volume
of information.

 The core component of the database is a table.

 A database table is composed of records and fields that hold data.

 Each table in a database holds data about a different, but related, subject.

 A record is composed of fields and contains all the data about one particular
person, company, or item in a database.

 A field is a part of a record and contains a single piece of data for the subject of
the record.

 Microsoft Access is a Relational Database Management System (RDBMS) that
helps us to store information for reference, reporting, and analysis.

 Table is a collection of various records.

 A query is a question that you ask about the data in your table.

 A report is used to show and print selected information from a table in a

customized manner.

 Form is an object of database which shows only the information you want to see.

New Gateway to Computer Science Book -10 103

Opening Microsoft Access 2010

 Click on Start.
 Select All Programs.
 Choose Microsoft Office folder.
 Now choose Microsoft Access 2010 from the list.
 We will get windows with various choices.
 Select blank database and type the required database file name on the file name box.
 Finally click on Create button.

We can create table in various ways such as:
 Design view : to create custom table design
 Datasheet View : to enter data into datasheet
 Table Wizard: to select sample table
 Import Table : to import external data from other application format
 Link Table : to link to an existing data source

Creating Table in Design View

In this view, you can add, edit and delete fields in a table. You can create as many fields
as required and select the data types for each field, add field description, set primary key
field and set field properties like data entry rules, validations, etc.
 Click on Create Tab on menu.
 Click on Table Design Button.
104 New Gateway to Computer Science Book -10

 You will see the table designation windows .
 Enter fields name and it’s data type as below:

 Set field SN to Primary Key (Not allowed to duplicate data for SN) by Right Click on
that field and choose Primary Key

New Gateway to Computer Science Book -10 105

 Click Ctrl+S to save the table.
 Type the required table name and click on ok.



Data Types

Data type is a field property that specifies and limits what kind of data can be entered
into that field. For example, values that are stored in a text field can contain only letters,
numbers, and a limited set of punctuation characters. After you enter the valid field name,
it allows a user to select the data type for the field. You can use the data type property to
specify the type of data stored in a table field such as text for name field, number for class
field, date and time for DOB field, etc. Each field can store data consisting of only a single
data type. The various data types are given below.

Data Description Maximum Default
Type Data Field
Text It is used for text or combinations of text / Space Size
and numbers as well as numbers don’t
Memo require calculations, such as phone num- Up to 255 50 (2003
Number bers.
Byte Characters Version)
Integer It is used for lengthy text and numbers.
255
It is used for data to be included in
mathematical calculations. (2007/10
It stores numbers from 0 to 255 without
decimals. Version)
It stores numbers from -32768 to +32768
without decimals. Up to 65,536 _

Characters

1,2,4 or 8 Long Integer
Bytes

1 byte

2 bytes

106 New Gateway to Computer Science Book -10

Long It stores numbers from -2147483648 to 4 bytes
Integer
Single +2147483647 without decimals.

Double It is a single precision floating point num- 4 bytes, 7
bers from -3.4 × 10- 38 to 3.4 × 1038. decimal
Date/Time
Currency places
Auto
Number It is a double precision floating point 8 bytes, 15
Yes/No
OLE Object numbers from -1.797 × 10-308 to 1.797 × decimal

Hyperlink 10308. places
Attachments
It is used for dates and time data. 8 Bytes
Lookup
Wizard It is used for currency values. 8 Bytes Long Integer

It is used for unique sequential 4 Bytes _

(incrementing by 1).

It is used for data that can be only one of 1 Bit _
two possible values, such as Yes/No.

It is used for OLE objects (such as MS- Up to 1 GB _
Word documents, MSExcel spreadsheets,
pictures, sounds).

It is used for hyperlinks. Up to 64,000 _
Characters

You can attach data from other _ _

programs to this type of field, but you

cannot type or otherwise enter text or

numeric data.

It is used to create a field that allows you 4 Bytes _

to choose a value from another table.

Field Description

You can enter the description of each field in the description column. It helps you to
remember the use and purpose of a particular field. This is an optional part in a database.
It is displayed in the status bar when you select this field on a form.

New Gateway to Computer Science Book -10 107

Primary Key

The primary key uniquely identifies each record in the table. Primary key does not accept
null (0) value. It can either be a normal attribute that is guaranteed to be unique (such as
class roll number in a table with no more than one record per person). Primary keys may
consist of a single attribute or multiple attributes in combination. Primary key are used
for:

 to uniquely identify a record, as every primary key value must be unique.
 to ensure every record has a key, as a primary key cannot be left blank.
 to be used in creating relationships.
 for sorting and searching records.
Setting the Primary Key
There are a number of ways to create a field as a primary key field. Some of them are,
 Select the field to be used as a primary key and select the Primary key button.
 Select the field to be used as a primary key and select the Primary key option from the
Edit menu.
 Place the cursor on the field selection cell and right click on it, then you can click on
Primary Key option from the list.

Note: If we do not select any key as a primary key and try to save the table, by default
access creates an auto number field that can be used as the primary key.

108 New Gateway to Computer Science Book -10

Field Properties

Field properties are the attribute that describe and
define a field. Field properties are the characteristics
which are related to each field. After creating a field
and setting its data type, we can set additional field
properties. For example, we can control the size of a
text field by setting its field size property. The field
size property also determines how much disk space
does each number field value require. Depending on
the field size, the number can use exactly 1, 2, 4, 8,
12, or 16 bytes.

Different types of field properties are listed below.

Field Property Purpose

Format It determines the way that the field appears when it is displayed or
printed in datasheets or in forms or reports that are bound to the
Decimal Places field. You can use any valid number format. In most cases, you
Input Mask should set the format value to currency.
Caption
Default Value It specifies the number of decimal places to use when displaying
Validation Rule numbers.
Validation Text
Required It displays editing characters to guide data entry. For example, an
input mask might display a dollar sign ($) at the beginning of the
field.

It displays the label text that is displayed for this field by default in
forms, reports, and queries. If this property is empty, the name of
the field is used.

It automatically assigns the specified value to this field when a new
record is added.

It supplies an expression that must be true whenever you add or
change the value in this field. It is used in conjunction with the
validation text property.

It displays when a value that is entered violates the expression in
the validation rule property.

It requires that data are entered in the field.

New Gateway to Computer Science Book -10 109

The Basic Properties of Fields

Field Size

You can use the field size property to set the maximum size for data stored in the field that
is set to the text or number data type. The default value of field size is 255. For numeric
data, the field size can be set depending upon the type and range of value you want to
store. The given table explains about the numeric data range and storage.

Field Size Setting Range of Values Decimal Storage Size
Places (in Bytes
Byte 0 to 255 None
Integer -32768 to 32767 None 1
Long Integer 2147483648 to 2147483647 None 2
Single -3.4 × 10-38 to 3.4 × 1038. 7 4
Double -1.797 × 10-308 to 1.797 × 10308 15 4
8

Format

It is basically used to specify the layout for a field. Format field property allows you
to display data in a format different from the way it is actually stored in a table. It is
also known as display layout for a field. The format property uses different settings for
different data types.

For Text and Memo Data Types

Format Symbol Meaning Format Setting
$
$ Indicates text character is optional @@@-@@-
@@@@
@ Text character in the form of character
or space or number not meant for &&-&&-&&
calculation is required. <
>
& Text character is not required.

< It converts all characters to lowercase.

> It converts all characters to uppercase.

For Numeric and Currency Data Types

You can format the number and currency data with predefined formats. You can choose the
pre-defined formats and many other symbols for creating your own customized numeric
and currency data format given below.

110 New Gateway to Computer Science Book -10

Format Meaning Data Entered Data
Setting Displayed
General
Number It displays number as entered 45689.123 45689.123
without changes. It is default for −33615.234 −33615.234
Currency number field.

Euro It displays the number with currency 255.45 $255.45
symbol with separator. It is default
Fixed for currency field.
Standard
Percent It displays number with Euro curren- 6455 €6,455.00

Scientific cy symbol and separator.

It displays at least one digit 3456.789 3456.79

It displays thousand separator. 456789.12 456,789.12

It displays the value multiplied by 2 200.00%
100 with added % sign. .22 22.00%

It uses standard scientific notation 2345.678 2.35E +03
with exponents.

For Date and Time Data Types

Setting Description/Example

General Date Here, if the value is date only, no time is displayed and if the value is
time only, no date is displayed. This setting is the combination of the
short date and long time. eg. 6/19/2012 (MM/DD/YYYY) and
7:34:23 PM (HH:MM:SS)

Long Date Long date setting, eg. Monday, August 25, 2012

Medium Date Medium date setting, eg. 26-Jun-07 (DD-MM-YY)

Short Date Short date setting, eg. 9/4/2012 (MM/DD-YYYY)

Long Time Long time setting, eg. 7:30:20 PM (HH:MM:SS)

Medium Time Medium time setting, eg. 7:30 PM (HH:MM)

Short Time Short time setting, eg. 17:34, 7:15 (HH:MM)

For Format String

Format String Data Entered Data Displayed
$#,##0.00 1234.56 $1,234.56
$#,##0.00 0 $0.00
##.00% 5.678 567.80%
##.00% 0 .00

New Gateway to Computer Science Book -10 111

For Logical (Yes/No) Data Types

A logical format allows only two possible values. The default setting is Yes/No. You can
use format as Yes/No or ON/OFF or True/False which displays with checkbox. A checked
checkbox represents Yes or True or On. An unchecked checkbox represents No or False
or Off.

Input Mask

Input Mask is a field property that determines what kind of data can be entered in the field
how it looks and how can it be entered in a field. It is simply the control over the data
entry. The task of input mask are:
 It helps to enter field values in a specified pattern.
 It can fill in constant characters like dash (-), parenthesis ( ) and slash (/) and optionally
store these characters as part of the field value as you do not have to enter these characters
at the time of data entry.

Create your own (custom) Input Mask

Input mask wizard can be the easiest option for certain fields like, pin code, phone
numbers, date and time. You can create your own input masks if you need to format other
kinds of values. The rules for creating input masks are :

 It contains three possible parts, separated by semicolons (;).

 It uses special characters in a mask to impose limits on what can be entered in a
field.

Input Mask Characters

The input mask characters are used to indicate how to limit the data that gets entered in a
field. The following input mask characters are allowed to use in the input mask.

Character Description/Function
0 Number is entered and required (0-9), no plus or minus sign.
9 Number is entered and optional (0-9), no plus or minus sign.
# Optional number or space, plus and minus sign is allowed.
L Letter is entered and required (A-Z).
? Letter is entered and optional (A-Z).
A Letter or number entered and required.
a Letter or number entered and optional.
& Any character or space required.

112 New Gateway to Computer Science Book -10

C Any character or space optional.
<
> Characters get converted to lowercase.
!
Characters get converted to uppercase.
\
A mask that displays characters from right to left but characters are
Password always entered left to right.
The mask helps display the next character in it as constant; for
example \B appears as B.
Creates a password entry text box. Any character typed in the text
box is stored as the character but is displayed as an asterisk (*).

Caption

Adding captions to fields helps both you and future database administrators to understand
the design and content of your database. It is one of the most common filed properties of
all data types. It is used to assign a descriptive name for a field. The maximum size for
this is 2048 characters. If caption is not entered, field name is used for label for a field on
a form.

Default Value

Default value field property displays the value automatically for the field when you add
a new record to the table. Default value can be changed during the data entry time. For
example, if you want to add records of class 10 students, in the class field you can set
the default value as 10 so that you do not have to enter the class each time you enter the
records.

Validation Rule

A validation rule limits or controls what users can enter in a table field or a control on a
form. Access provides several ways to validate data, and you often use several of those
techniques to define a validation rule.

Types of Validation Rules

Field Validation Rules

It uses a field validation rule to check the value that you enter in a field when you leave
the field. For example, suppose you have a date field, and you enter >=#01/01/2017# in
the validation rule property of that field. Your rule now requires users to enter dates on or
after January 1, 2017.

New Gateway to Computer Science Book -10 113

Record (or table) Validation Rules

It uses a record validation rule to control when you can save a record (a row in a table).
Unlike field validation rules, record validation rules refer to other fields in the same table.
You create record validation rules when you need to check the values in one field against
the values in another.

Expression Example Description

Validation expression for numbers

< <100 Entered value must be less than 100.

> >50 Entered value must be less than 50.

<> <>0 Entered value must not be equal to 0.

<= <=100 Entered value must be less than or equal to 100.

>= >=50 Entered value must be less than or equal to 50.

= =10 Entered value must be equal to 10.

Between ... and .. Between 0 Entered value must be within the range of 0 to 100.
and 100

Validation Text

Validation text is a field property which displays the error message when the user fails to
use the validation rule. If the data entered is invalid according to the specified validation
rule it displays the validation text.

Required

Required property is used to specify whether a value is required in a field or not. So, Yes
and No are the options for required property. If this property is set to Yes for a field, the
field must receive a value during data entry. If this property is set to No for a field, the field
can be left blank without any value during data entry.

Allow Zero Length

Allow zero length property is only for the text and memo data types. This property works
with the required property. If you set the required property to ‘Yes’ and allow zero length
to ‘No’, data must be entered during data entry.

Indexed

This property speeds up searching and sorting of records based on a field. For example,
if you search for specific student name in the first name field, you can create an index for
this field to speed up search for the specific name. Default indexed property is set as No.
It also uses other two settings.

114 New Gateway to Computer Science Book -10

Let’s Review
 In design view, you can add, edit and delete fields in a table.
 Data Type is a field property that specifies and limits what kind of data can be
entered into that field.
 Field description helps you to remember the use and purpose of a particular field.
 The primary key uniquely identifies each record in the table. Primary key does
not accept null (0) value.
 Field properties are the attributes that describe and define a field.
 You can use the field size property to set the maximum size for data stored in the
field that is set to the text or number data type.
 A logical format allows only two possible values. The default setting is Yes/No.
 Input mask is a field property that determines what kind of data can be entered in
the field how it looks and how it can be entered in a field.
 Default value field property displays the value automatically for the field when
you add a new record to the table.
 A validation rule limits or controls what users can enter in a table field or a control
on a form.
 Validation text is a field property which displays the error message when the user
fails to use the validation rule.

Working with Table

As we discussed above, table is the basic object of database.
Without creating table, we will be unable to create a database.
Now, we will discuss about creating table in database.
There are various ways to create a table. The various ways
of creating tables are explained below.

Creating table using design view

After creating a blank database, we need to create a table.
The steps are as follows:
 Create a database file.
 Click on Create tab.
 Choose Table Design from the ribbon.
 A blank table will display.

New Gateway to Computer Science Book -10 115

 Type the required Field name and Data type.

 Press CTRL + S to save the table under a new name.
 Type the required name for Table Name and click on OK .
(Note: If you want to set primary key , press ‘Yes’ button or press ‘No’ button if you don’t
want to set primary key.)
To enter records on table:
 Double click on the table name.

 You will get a table that you have created with the name of fields.
 Enter records on the table and press CTRL + S again to save it.

116 New Gateway to Computer Science Book -10

To modify the fields on the table:
 Right click over the name of table.

 Select the Design view option.
 Now you will get the previous design box, you can change the structure of the table as
required and press CTRL + S to save it.
Working with Lookup Fields:
 Open the table on design view.
 Set the field data type as Lookup Wizard.
 A box will display as below.

 Select the option “I will type in the values that I 117
want” and click on next button.
 Enter the value for number of columns and
type the values on column. Press Tab button
to change the row.
 Finally click on Finish to apply it.

New Gateway to Computer Science Book -10

Creating Table Using Datasheet View:
 Open any database.
 Choose the Table command in the Tables group on the Create tab.
 Add your table fields.

 Next, for each field you add, you’ll want to check and change the assigned data type.
 Select the first field.
 Show the Data Tools Datasheet Contextual tab.
 Check, and if necessary, change the Data Type and Format in the Data Type &
Formatting group
 Repeat the steps as before.
 Click the Save command on the Quick Access Toolbar.
 Enter a table name.
 Finally click on OK.
Adding Records in a Datasheet
 Open datasheet, type the required data in the field.

 Press Tab or Arrow to move to the next field. Or, simply place the mouse cursor in
the desired field.
 While entering the data in a field next row for next record will be automatically
displayed. Repeat the above steps to enter the data in fields till it is required.
 After finishing adding records in the datasheet, you can close the datasheet
simply by clicking on File tab and select Close option.

118 New Gateway to Computer Science Book -10

Modify Records in a Datasheet
 Place the mouse cursor at the required location.
 Select the content of the cell that you want to change.
 If you want to change the part of the cell content, place the mouse cursor in the desired
insertion point within the cell and use backspace key or delete key of the keyboard
as required and enter the new content.

Delete Records from a Datasheet

To remove the unwanted records from the datasheet, you can use this options. The contents
of cell can be deleted by selecting and pressing the delete button on keyboard.
 To delete the record :
 Position the cursor and select the record or records (rows) that you want to delete.
 Select Delete record option that appears when you click the right button on mouse.
 To delete the fields:
 Position the cursor over the field name and select the field or fields (columns) that
you want to delete.
 Select Delete Field option that appears when you click the right button on mouse.
 Computer will ask for confirmation whether you want to delete or not.
 Click on ‘Yes’ option to delete the records or fields.

Hiding the Columns or Fields

You can temporarily hide a column(s) or field(s)
so that you can view more columns in a larger
datasheet. Steps to hide column(s) in datasheet
are as follows.
 Position the cursor on the column heading
(field name) and click the right button to
open the shortcut menu.
 Select and click on Hide Fields.

Adjusting Column Width

We can adjust the column width as required to fit the data in the field. By dragging the
field sizing line from the right most corner of the field header also we can adjust the
column width.

New Gateway to Computer Science Book -10 119

 Double clicking on the field sizing line.
 Set the fixed width in a column width
dialog box. We can also use the best fit
option in the dialog box that automatically
adjusts the required size of the column.
The standard width option is 11.75 in MS-Access
2010.
Adjusting Row Height
We can set the row height in a Row Height dialog
box. We can select the Standard Height option in the
dialog box that automatically adjusts the standard
height of the row that is 14.25 in office 2010 version.
Sorting Records
The process of arranging all the records in a table either in ascending or descending order
based on field or fields is known as sorting.
 Text types of data are sorted in an alphabetical order (ie. A to Z).
 Date and Time data are sorted from oldest to newest.
 Number/Currency types of data are sorted in smallest to largest order.
The steps for sorting the data are:
 Open the table.

 Click on Home tab and over click on the field name.
 Select the required option as required.
 Sort smallest to largest or Sort largest to smallest as above.

120 New Gateway to Computer Science Book -10

Filtering Records
Filtering is the process of viewing required record of a table that matches the specified
criteria. While filtering, you can use criteria to search values in one or more than one field.
We can use the following options to filter the record.
 Filter by selection
 Filter by form
 Advance Filter or sort

Creating a Relationship
A primary feature of relational databases is that they contain multiple tables, each of
which can have a relationship with any of the other tables. Relationships are ties that are
created between tables in the database so that MS-Access can combine data from more
than one table to create reports. It is how tables determine how they correspond to each
other. To create a relationship, first we have to create the related tables as below.

Be sure to set a format and default value for the date created fields on both tables (you
shouldn’t need to enter this field - the system can do that). Now, to create the relationship
between all three tables we can do as below.

New Gateway to Computer Science Book -10 121

 Click on Design, and select the Relationships options.

 A Show Table dialog box will appear,
displaying all three tables. Select all of them and
click Add.
 Click Close to close the dialog box.
 You will now see three boxes which
represent your three tables. Click and drag the
CustomerId from the Customers table cross to the
corresponding CustomerId field on the orders table.

 The Edit Relationships dialog will appear. Click Enforce Referential Integrity so that
it is checked. Check that the values are the same as the following screenshot and click
OK.

122 New Gateway to Computer Science Book -10

 You will now see a line established between the CustomerId field on the Customers table
and the CustomerId on the Order stable.

 Now do the same for the Products table. That is, click and drag the ProductId from the
Products table across to the corresponding ProductId field on the Orders table.

Types of Relationship

 One-to-one relationship: For each record in one table, there is one and only one
matching record in a different table. It is as if two tables have the exact same primary
key. Typically, data from different tables in a one-to-one relationship will be combined
into one table.

 One-to-many relationship: For each record in one table, there may be zero, one or
many records matching in a separate table. For example, you might have an invoice
header table related to an invoice detail table. The invoice header table has a primary
key, Invoice Number. The invoice detail table will use the invoice number for every
record representing a detail of that particular invoice. This is certainly the most
common type of relationship you will encounter.

 Many-to-manyrelationship:ThisrelationshipcannotbedefinedinMS-Accesswithout
the use of a mapping table. This relationship states that records in both tables can
have any number of matching records in the other table.

Query on Database

Queries are database objects that can be used to retrieve information from multiple tables
by joining these tables using common fields. Simply, queries are used to change, view,
and analyse the data. In MS-Access you can use queries to extract information (data)
from one (or more) tables (or from other queries). For example you can write a query
that returns all students that have a percentage that is less than 40. Besides limiting the
number of records with queries, you can also limit the number of columns (fields). For
example instead of returning all fields from the student table you can only select the
student ID, Student Name, Student percentage and Student email address.

New Gateway to Computer Science Book -10 123

There are different types of queries, they are:
 Select Query
 Parameter Query
 Crosstab Query
 Action Query
 SQL Query

Select Queries

A query asks a question about data
stored tables and returns a result set
in the form of a datasheet without
changing the data. It retrieves data
from one or more tables and displays
the results in a datasheet where we
can update records. A select query
can contain specifications for the
fields (columns) to return, the records (rows) to select, the order to put the records in, and
the way to group (summarize) information. Select query can be used to:
 view subset of records.
 retrieve data form one (or more) tables.
 display the results in a datasheet.
 update the records from within the datasheet.

Parameter Queries

A parameter query is a query that displays a
dialog box prompting users for information, that
information can be used for retrieving records or a
value you want to insert in a field. You can design
the query to prompt you for more than one piece of
information; for example, you can design a query
to prompt a user for two dates (beginning and end
date). Access can then retrieve all records that fall
between those two dates. Parameter queries are also
can be used as the basis for forms, reports, and data
access pages. For example, you can create a monthly

124 New Gateway to Computer Science Book -10

earnings report based on a parameter query. When you print the report, Access displays a
dialog box asking for the month that you want the report to cover. You enter a month and
MS-Access prints the appropriate report.

Crosstab Query

Crosstab query is used when you want to calculate and restructure summary data to make
it easier to read and understand. Crosstab queries calculate a sum, average, count, or other
type of aggregate function to calculate data that is grouped by two types of information
one down the left side of the datasheet and another across the top. If you want to use
values from a Date/Time field for column headings, but want to group the dates into
intervals that the wizard does not provide, such as fiscal year or biennium, do not use the
wizard to create your query. Instead, create the crosstab query in design view, and use an
expression to create the intervals.

Action Query

An action query is a query that makes changes to or removes many records in just one

operation. Below are the four different types of action queries.

 Delete Query

 Update Query

 Append Query

 Make Table Query

Delete Query: A delete query deletes a record or group of records from one or more
tables. For example, you can delete the records of those students who have got marks less
than 40 in each subject in the marks database.

Update Query: An update query makes entire changes to a record or group of records in
one or more tables. For example, you can change the class of students from 9 to 10 when
students are promoted to 10th grade in the student database. With an update query, you
can change data in existing tables.

Append Query: An append query adds a group of records in one or more tables to the end
of records. For example, suppose that some new students have been admitted in school
and you need to keep the records of those students in the school’s database. To avoid
typing all this information into your database, you’d like to append it to your students
table of school’s database.

New Gateway to Computer Science Book -10 125

Make-Table Query: Make-table query creates a new table from all or part of the data in
one or more tables.
Structured Query Language (SQL)
You can use SQL to query, update, and manage relational databases such as MS-Access. In
MS-Access you can write queries in SQL format. Queries written in SQL are also known
as SQL statement. When you create a query in design view, MS-Access automatically
makes the equivalent SQL statement. You can view it selecting the SQL view shortcut
menu option. In below figures, you can see two queries created in design view option and
their equivalent SQL query. In MS-Access you can write queries in SQL format. Queries
written in SQL are also known as SQL statement. When you create a query in design
view, MS-Access automatically makes the equivalent SQL statement. You can view it
selecting the SQL view shortcut menu option. In below figures, you can see two queries
created in design view option and their equivalent SQL query.

Creating Queries Using Design View
 Select the queries object from the database window.
 Select and click on Query Design option from Create menu.
 You can see the Show Table dialog box.
 Select and add the source for designing
query. Source can be Tables or existing
queries
or both. After you add table as a source it
displays as below.
 Double click on the field(s) or simply
drag the field(s) to the bottom half of the
window in the proper order that you want
to view in query datasheet.

126 New Gateway to Computer Science Book -10

 Click on Run option to view the result of the query created.

 You can also set conditions in the criteria
section on the bottom half of the window.
For example, if you want to view only
the records of passed students you can
give criteria as >=40.

After you follow all the above mentioned steps, for all the queries except select query
you have to select from shortcut menu list or from the quick access toolbar as shown in
the figure.

Wildcard characters and operators in query

Wildcards/ Example Meaning
Operators
# Represents any single digit, 0-9.
>
>50 Shows the record where the specified field is
<
greater than 50.
>=
<100 Shows the record where the specified field is less
<=
than 100.
<>
>=100 Shows the record where the specified field is
Between.... greater than or equal to 100.
And
<=400 Shows the record where the specified field is less
In than or equal to 400.

<>20 Shows the record where the specified field is not
equal to 20.

Between Shows the record between 02/04/10 to

#02/04/10# 04/07/12 date.

And #04/07/12#

In(“Gita”, “Dee- Shows the record that has the field value as

pa”) Gita or Deepa.

New Gateway to Computer Science Book -10 127

AND >60 And <=80 Shows the record that has specific value from 61
OR to 80
“Bus” OR
“Train” Shows the record that has specific value as Bus or
Train.

Query Calculation Sample

Prepare a query that displays those student’s record who have secured more than 90 in
computer.

 Create a database and create a table in design view with the information such as
Student Roll , Name , Class, Math , Computer, English and Social then save the table.

 Click on Create tab and select Query Design option.

 Add the table and add the table field by double clicking over it.

 Set the criteria as >90 under the computer field and save it.

 Now, just click on the query, then you can see those records who have secured more
than 90 in computer.

Working with Forms

Form is a type of database object
mostly used to create an interface for
entering data in a table or multiple
linked tables. Forms are basically
GUI (Graphical Users Interface) using
which users interact with MS-Access
database. Form also displays complete

128 New Gateway to Computer Science Book -10

record one at a time, with the help of form you can view and modify records. Forms in
MS-Access are created using the given options.
 Create form in design view.
 Create form by using wizard.

Creating Form by Using Wizard

The wizard enables you to select the fields from a table or
multiple linked tables, layout, and user interface for the form.
You have to follow the given steps to create forms using the
wizard option.

 Select the Forms object from the database
window.

 Select and click on Form Wizard option
from Create menu.

 After this it displays the Form Wizard
dialogue box as shown in the figure.
Here, at first you have to select the existing
tables or queries from the drop down list.

 Now, you have to select the fields that you want to keep in the form from the
Available Fields box. To select fields as per the requirement, click on field option in
the Available Fields list and click on single arrow button.

You can also select all the available fields at once by clicking on double arrow button.

 Click on Next button.

 Inthenextdialogueboxasinthefigure,youcanselect
the layout of the form. The available options for the
layout are Columnar, Tabular, Datasheet and
Justified. After choosing the layout click on Next
.

 Apply suitable title for the form. By default
MS-Access gives the title of table or query
hosen for the creation of form. Finally click on the Finish button. Here you can still
change the form design if you select Modify the form design and click on the Finish
button. If you do so it opens the form in design view.

New Gateway to Computer Science Book -10 129

Entering Data Using a Form

After the form is created, you can enter the
data simply typing in the text box. Whereas
MS-Access form also contains various control
options while entering the data. These control
options are, Text box, Combo box, List box,
Check box, Label, Command button, Tabcontrol,
Image, hyperlink etc. Steps to add records in
form datasheet are as follows.

 After you open form datasheet mouse cursor
will be placed in the first field of first record. Type the required data in the field.

 Press Tab or enter to move to the next field. Or, simply place the mouse cursor in the
desired field.

 When you finish entering the all the data for the first record, MS-Access automatically
prompts for entering the second record and so on.

Working with Report

Report is a type of access database object
used to present information in an effective
and organized format that is ready for
printing. Using the report, you can display
the information the way you want to view
it. Create report by using wizard.

Creating Report by Using Wizard

The wizard enables you to create a
report in a desired format. The report
wizard provides you to choose the
tables and fields, group the data, sort
the data, summarize the data, choose
a layout and orientation, apply a style,
and title your report.
 Select the Reports object from the
database window.

130 New Gateway to Computer Science Book -10

 Select and click on Report Wizard option from Create menu.

 After this it displays the Report Wizard
dialog box as shown in the figure. Here, at first
you have to select the existing tables or queries
from the drop down list.

 Now, you have to select the fields that you
want to keep in the form from the available
fields box. To select fields as per the
requirement, click on field option in the available
fields list and click on single arrow button or double
arrow button. After selecting fields click on Next button.

 On the next wizard screen, you can further group
records in the report by a particular
field. To group by a field, click the field and then
click the arrow button. You can select
several grouping levels in the order you want them.
Then click Next to move on.

 The wizard then asks whether you would like to
sort the records in the report as in figure.

 If you want to sort the records by a particular field
or fields, open the top drop down list and select a
field to sort with and click Next button.

 Now, in the next dialog box, you can select the
layout of the form then click on Next button.

 Now, you have to give the title of report.

 Finally click on the Finish button.

You can change the report design if you select Modify the report design and click on the
Finish button. If you do so it opens the report in the design view.

 The final report will display as below.

New Gateway to Computer Science Book -10 131

Let’s Review
 You can temporarily hide a column(s) or field(s) so that you can view more
columns in a larger datasheet.

 Filtering is the process of viewing required record of a table that matches the
specified criteria.

 Relationships are ties that are created between tables in the database so that
Ms-Access can combine data from more than one table to create reports.

 Queries are database objects that can be used to retrieve information from multiple
tables by joining these tables using common fields.

 A query asks a question about the data stored tables and returns a result set
in the form of a datasheet without changing the data.

 A parameter query is a query that displays a dialog box prompting users for
information, that information can be used for retrieving records or a value you
want to insert in a field.

 Crosstab query is used when you want to calculate and restructure summary data
to make it easier to read and understand.

 The types of action queries are delete query, update query, append query and make
table query.

 An update query makes entire changes to a record or group of records in one or
more tables.

 You can use structured query language to query, update, and manage relational
databases such as MS-Access.

 Queries written in SQL are also known as SQL statement.

 When you create a query in design view, MS-Access automatically makes the
equivalent SQL statement.

 Form is a type of database object mostly used to create an interface for entering
data in a table or multiple linked tables.

 Report is a type of access database object used to present information in a
effective and organized format that is ready for printing.

132 New Gateway to Computer Science Book -10

Innovative Task
 Visit any organization nearby you and observe what type of database
management system they are using.

 Prepare a short project report about what types of software programs are being
used in your school for accounting, result processing and attendance system.

Assignment

1. Choose the correct answer.

a. Access is used to develop

i. DBMS ii. software iii. Database iv. Word

b. What is the extension of Access database file?

i. DB ii . MDB iii. DBF iv. ADB

c. The name of caption can be declared upto

i. 2048 characters ii. 2063 characters

iii. 64,000 characters iv. 2005 characters

d. The logical data type of access is

i. Yes/no i. True/False iii. on/Off iv. All of the above

e. The OLE object can store graphics, sound upto….GB:

i. 1 ii. 2 iii.3 iv. 4

f. Which of the following is not a relational database?

i. dBase IV ii. FoxPro iii. Oracle i v. Reflex

g. Which of the following is a field property?

i. Indexed ii. Field Size iii. Caption iv. All

h. Integer needs ……..bytes space to store its values.

i. 8 ii. 2 iii. 3 iv. 4

i. Default field size of “Number” data type is:

i. Integer ii. Long Integer iii. Auto Number iv. Byte

j. Size of database are usually measured in term of:

i. Kilobyte ii. Terabyte iii. Megabyte iv. Gigabyte

New Gateway to Computer Science Book -10 133

k. Which of the following is not field property?

i. Indexed ii. Field Size iii. Colour iv. Format

l. MS-Access 2010 can support ………types of data.

i. 9 ii. 8 iii. 10 iv. 12

m. A piece of information about a object or individual is called …….

i. Form ii. Field iii. Record iv. Report

n. …. accelerates the query and sort operation.

i. Index ii. Sort iii. Number iv. Filter

o. The field size of logical field is ……. bit in MS-Access.

i. 0 ii. 1 iii. 2 iv. 3

p. Field Name can be up to ……………… characters long.

i. 64 ii. 16 iii. 128 iv. 40

q. The default field size of “AutoNumber” data type is ………………

i. Byte ii. Integer iii. Long Integer iv. Double

r. Which is a data type of MS-Access?

i. Memo ii. Hyperlink iii. Lookup Wizard iv. All

2. Write true or false for the following statements.

a. OLE is a data type of Ms- Access.

b. We cannot enter duplicate value in the primary key field.

c. Cell is interconnection of rows and columns.

d. We can use ‘auto number’ data type for salary field.

e. The appropriate field type to store “Date of Birth” is date and time.

f. Form is designed for data input.

g. True/ False is a logical data type.

h. Hyperlink data type occupies up to 2042 characters.

i. The logical data type of access is Yes / No.

j. Index accelerates the query and sort operations.

134 New Gateway to Computer Science Book -10

k. Only one table can be created in MS- Access.

l. Hyperlink is a field property.

m. Maximum field size of memo field is 256 characters.

n. A collection of record for a single subject is a table.

o. Caption is a database object.

p. Report is an object that allows to define print format.

3. Fill in the blanks with correct words / phrases.

a. dBASE is an example of ………

b. A table is a part of ……

c. The default size of text field is ………

d. …………helps to print the output through the printer.

e. ………….is suitable data type for picture Field.

f. Large collection of files is called ………….

g. Ms-Access is a ………..software.

h. The Yes/No data type need ……..space to store its value.

i. ………….is suitable data type for Roll_ NO field.

j. The value automatically enters for the new record is …………….

k. The primary key does not accept …….. value.

l. …………….. is an expression that limits the value to be entered in the field.

m. …….. is an object of MS-ACCESS that allows to enter, edit and view data.

n. …….is the data type that allows to store up to 65,535 characters.

o. Update query is a type of ……….query.

4. Match the followings.

a. Data Redundancy i. Error Message

b. Validation Text ii. Input Mask

c. Field Properties iii. Lookup Wizard

d. Validation Rule iv. Data Repetition

v. Limits the values

New Gateway to Computer Science Book -10 135

5. Answer the following questions.
a. Define DBMS with example.
b. What is a primary key? What is the importance of primary key in MS-Access?
c. Why is report created? How you can create using report wizard? Write with steps.
d. Define database and DBMS.
e. What is data sorting? How does it differ from filtering?
f. What is a form? Write any two advantages of forms.
g. Define Database Management System (DBMS). List some of the popular DBMS.
h. Differentiate between a database and a table.
i. Write the importance of using form in access.
j. Define relational database management system with its examples.
k. What is a report? What is the purpose of a report in MS-Access?
l. What is a database? Define table and report.
m. While designing table structure which data types are suitable to store information
about teacher’s name, address, salary and data of birth?
n. Write down any two advantages of query.
o. Define database and DBMS with one example of each.
p. How can data redundancy be controlled in MS- Access?
q. What is the importance of using query in MS-Access?
r. What is a select query?
s. What does field size mean? Name any two data type that can be defined in MSaccess.
t. Define relationship with its types.

136 New Gateway to Computer Science Book -10

Programming Language

Unit

3

This unit covers the following lessons:


Lesson 8 : Review on Qbasic Programming
Lesson 9 : Modular Programming in QBASIC
 Practical Section on SUB Procedure
 Practical Section on FUNCTION Procedure
Lesson 10 : File Handling in QBASIC
 Practical Section on File Handling
Lesson 11 : Programming in C
 Model Question Paper
 List of Abbreviations

Lesson

8 Review on Qbasic Programming

Learning Outcomes

At the end of this lesson, students will be able to:
 define Qbasic programming and tell its features.
 explain the Qbasic operators.
 identify the Qbasic statements with syntax.
 explain the types of control statement.
 write Qbasic programming using some control statements.

QBasic is a high level programming language developed by Microsoft Corporation
for use in the MS-DOS operating system in 1985. It is the successor of earlier version of
BASIC (Beginners All-purpose Symbolic Instruction Code). It is a programming language
for beginners because of its in-built commands, simple structure and flexibility. It is also
called as a modular programming language where program is divided in different
modules or procedures. It uses English like keywords and mathematical symbols to
write a program. QBAISC screen has two types of windows they are program window and
immediate window. Program window is the upper window which is titled as ‘Untitled’
where we can write programs. To see the output of the statements written in this window,
we have to press Shift + F5 key. Like this, immediate window is the lower window
which is titled as ‘Immediate’. It is the window to test commands, expressions, etc. When
we press the enter key, it displays the output on the screen.

Features of QBASIC

 It is simple and easy to learn and understand.
 It automatically checks syntax.
 It allows you to divide large programs into modules.
 It has dynamic program debugging feature.
 It supports local and global variables.

138 New Gateway to Computer Science Book -10

QBASIC Operators

Operators are the symbols that indicate the type of operation that has to be performed on
the data or on the values of variables. There are four types of operators in QBASIC. They
are Arithmetic Operators, Relational Operators, Logical Operators and String Operator.

Arithmetic Operators

Arithmetic Operators are used to perform mathematical calculations like addition,
subtraction, division, multiplication and exponential. The following table shows arithmetic
operators used in QBASIC.

Operation Operator Example Output

Addition + Sum = 3 + 4 Sum = 7

Subtraction - Diff = 10-5 Diff = 5

Multiplication * Product = 10*10 Product = 100

Floating Point Division / Div = 5/2 Div = 2.5

Integer Division \ Div = 11\5 Div = 2

Exponential ^ Exp = 2 ^ 5 Exp = 32

Modulus Division Mod Mod = 5 MOD 2 Mod = 1

Relational Operators

Relational operators are used to perform comparisons on two values of same type. A
comparison of sting data with numeric data cannot be done. The comparison of sting data
is done on the basis of ASCII value. The result of comparison is either true or false. The
following table shows the relational operators used in QBASIC

Name of Operator Relation Example
= Equal to 5 = 5 , A = B , A$=B$
> Greater than
< Less than 10>5, A>B
>= Greater than or equal to 5<10, B<A
<= Less than or equal to 10>=5, A>=B
<> Not equal to 5<=10, B<=A
6<>5 , A<>D

Logical Operators

Logical Operators combine two or more relational expressions to evaluate a single value
as True or False. The result of evaluation is used to make decisions about the program
flow. The commonly used logical operators in QBASIC are AND, OR and NOT.

New Gateway to Computer Science Book -10 139

AND Operator

AND operator returns ‘True’ when all the results returned from individual relational
expressions are ‘True’ otherwise it returns ‘False’. The Truth Table of AND operator is
given below.

Input A Input B Output A AND B
False False False
False True False
True False False
True True True

OR Operator

OR Operator returns ‘True’ if any one of the relational expressions returns ‘True’. If all
the relational expressions returns ‘False’ then only the combined result returned by OR
operator will be ‘False’. The Truth table of OR operator is given below.

Input A Input B Output A OR B
False False False
False True True
True False True
True True True

NOT Operator

NOT Operator operates on one operand and returns ‘True’ if the logical operation returns
‘False’. The NOT truth table is as given below.

Input A Output NOT A
False True
True False

String Operators (+)

A string expression consists of string constant, string variables and other string
expressions combined by string operators. There are two classes of string operations.
They are concatenation and string function. The act of combining two strings is called
concatenation. The plus (+) symbol is the concatenation operator for string. For example,
the following program fragment combines the string variables A$ and B$ to produce the
value ShubharambhaPublication.

140 New Gateway to Computer Science Book -10

A$ = “Shubharambha” : B$ = “Publication”
Print A$+B$
Print “Our” + A$+B$
The output is :
From Print A$+B$: ShubharambhaPublication
From Print “Our” + A$+B$: OurShubharambhaPublication

Assignment Operators (=)

The assignment operator evaluates an expression on the right of the expression and
substitutes it to the value or variable on the left of the expression. For Example : x = a +
b, Here the value of a+b is evaluated and substituted to the variable x.

QBASIC Statements

REM Statement: REM is a non-executable statement that is used to insert explanatory
remarks for the program that we are writing. It can be used at any part of the program. The
general format of REM statement is given below.

REM <remark> Here, remark may be any statement or phrase to define the program.

CLS Statement: This statement is used to clear the previous output from the display
screen and makes the screen blank. This command is given before the starting of any new
program. The general format of CLS statement is given below.

<CLS>

LET Statement: This statement is used to assign the value in the variable. It is also called
assignment statement. This is also an optional statement is Qbasic. The general format of
CLS statement is given below.

LET <variable> = <expression> Here, variable is the name of a numeric or string variable
which receives the value and expression is a numeric or string expression whose value
will be assigned to a variable.

INPUT Statement: This statement is used to receive input data from the keyboard during
the execution of the program. It will prompt the user to input data and then place the
inputted data into a variable. INPUT string and the variable must be separated by either
a comma or a semicolon. The semicolon will print a question mark at the end of the text.
The general format of INPUT statement is given below.

INPUT [“Message”] ; list of Variables Here, message is a string constant enclosed in a
double quotes and list of variables contain the numeric or string variable which stores the
data input by the user.

New Gateway to Computer Science Book -10 141

PRINT Statement: This statement is used to display the output on the screen. Question
mark (?) also can be used instead of PRINT statement to display on the screen. The
general format of PRINT statement is given below.

PRINT[list of expressions][{; | ,}]

END Statement: This statement is used to indicate the end of the QBASIC program to
terminate it.The general format of END statement is given below.

<END>

PRINT USING Statement: This statement is used to display string or number using a
specified format. The general format of PRINT USING statement is given below.

PRINT USING string expressions;list of expressions[;] Here, string expressions
is a string literal or variable consisting of special formatting characters. The formatting
characters determine the field and the format of printed strings or numbers and list of
expressions consists of the string or numeric expressions separated by semicolons.

The string formatting characters are given in the table below.

! Displays only the first character of string.
\n\ Prints first n+2 characters from the string.
& Displays all the string.
# Digit position is specified.
&& Prints leading & sign.
^^^^ Prints the number in exponential format.
. Decimal point position specification.

LINE INPUT Statement : This statement allows to input line of data at a time and assign
in to single variable. The general format of LINE INPUT statement is given below.

LINE INPUT “prompt”; variable Here, prompt is a string constant that will be displayed
when the statement is executed and variable is the name of a string variable or array
element to which the line will be assigned.

LPRINT and LPRINT USING Statement: The LPRINT statement is used to print the
text to a printer and the LPRINT USING statement is used to print formatted output to a
printer. The general format of LPRINT and LPRINT USING statement is given below.

LPRINT [expression [, \; expression]……] [;]

LPRINT USING “string”: expression [, \;expression]…... [;] Here, expression is a numeric
or string to be printed and string is a string constant or variable that identifies the format
in which expression is to be printed.

142 New Gateway to Computer Science Book -10

READ….DATA Statement: This statement is used to read values from the DATA
statement and assign them to variables. It is used mostly when dealing with large quantities
of data in program. The DATA statement is to store the numeric and string constants that
are accessed by the READ statement. The general format of READ…..DATA statement
is given below.
READ [Variable1, variable 2, variable 3…..]
------
------
------
DATA [constant1, constant2, constant 3….

RESTORE Statement: The RESTORE statement is used to reset the DATA pointer to
the beginning of the data. Once the data element is read, it cannot be read again until the
program resets it. The RESTORE statement is used to reset the data in the program. The
general format of RESTORE statement is given below.

RESTORE[line number] Here, If the line number is specified, the next READ statement
accesses the first item in the specified DATA statement and if the line number is omitted,
the next READ statement accesses the first item in the first DATA statement.

LOCATE Statement: This statement is used to move the cursor to the specified position
on the screen.

LOCATE [row][,[col][,[cursor][,[start] [,stop]]]] Here, row is the screen line number, col
is the screen column number, cursor is a Boolean value indicating whether the cursor is
visible or not. Start is the cursor start scan line, stop is the cursor stop scan line.

SWAP Statement :This statement is used to exchange the values of two variables. The
general format of SWAP statement is given below.

SWAP variable1, variable2

Types of Control Statements

Branching Statement

Branching statement is a decision making statement. Depending upon the decision
branching statement can change the order of execution. Branching statements are divided
into two types.

Conditional Branching Statement

This statement allows the selective execution of statements based on a particular condition.
This statement directs the computer to another part of the program based on the results

New Gateway to Computer Science Book -10 143

of a compare. High-level language statements, such as IF….. THEN, IF…..THEN…..
ELSE, IF ... THEN ... ELSE IF, SELECT ... CASE, are the popular conditional branching
statements. We are going to discuss more about them.

IF ... THEN Statement
This statement is a decision making conditional branching statements which
executes a block of statements only if the given expression or condition is true. If
the condition is false, then the IF blocks will skip and execution continues with the
rest of the program.

Syntax :IF [conditional expression] THEN [statement block]

Practical Assignment

CLS
INPUT “Enter a number “; N
IF N MOD 2 = 0 THEN PRINT “It is Even Number”
IF N MOD 2 = 1 THEN PRINT “It is Odd Number”
END

IF ... THEN .... ELSE Statement

It is also a control statement which is used to execute multiple statements depending on
the condition. It is also called two way decision making statements. In this statement if
the condition is true the statements after THEN will be executed and if the condition is
false, the statements in the ELSE block will be executed.
Syntax :IF [conditional] THEN[statement 1]ELSE[statement 2]
……………….
END IF

Practical Assignment

CLS
INPUT “Enter first number “; A
INPUT “Enter second number “; B
INPUT “Enter third number “; C
IF A> AND A>C THEN
PRINT “The greatest number is”; A
IF B>A AND B>C THEN

144 New Gateway to Computer Science Book -10

PRINT “The greatest number is”; B
ELSE
PRINT “The greatest number is:”; C
END
IF ... THEN ... ELSEIF Statement

This statement is another form of IF….THEN…..ELSE statement. The conditions are
evaluated from top to bottom. The syntax is given below.
Syntax :
IF [condition] THEN
[statement 1]
ELSEIF
[statement 2]
ELSEIF
[statement n]
........................
.......................
ELSE
[statement n]

END IF

Practical Assignment

CLS
INPUT “Enter your percentage “; P
IF P>= 80 THEN
Result$ = “Distinction”
ELSEIF p >= 60 THEN
Result$ = “First Division”
ELSEIF p >= 40 THEN
Result$ = “Second Division”
ELSEIF p >= 35 THEN
Result$ = “Third Division”
ELSE
Result$ = “Sorry! No result found”
END IF

New Gateway to Computer Science Book -10 145

PRINT “Division ::: “; Result$
END

SELECT CASE Statement

This statement is a multi-way branching statement which makes the control jump to one
of the several statements based on the value of an expression.
Syntax :
SELECT CASE
CASE test 1
[statement1]
CASE test 2
[statement 2]
........................
.......................
CASE ELSE
[statements]
END SELECT

Practical Assignment

CLS
INPUT “Enter your choice (1 – 3)”; N
SELECT CASE N

CASE 1
PRINT “Baishak”
CASE 2

PRINT “Jestha”
CASE 3
PRINT “Ashad”

CASE ELSE
PRINT “Invalid Value”
END SELECT
END

146 New Gateway to Computer Science Book -10

Unconditional Branching Statement

Unconditional branching statement is used when the programmer forces the execution of
a program to jump to another part of the program. This can be done using the combination
of loops and if statements. You can avoid such unconditional branching and use this
technique only when it is very difficult to use a loop.

GOTO Statement

This statement in QBASIC is used to transfer the program control from one statement to
another. It is an unconditional branching statement.

Syntax : GOTO [line number / line label]
Practical Assignment

CLS
AA:
INPUT “Enter the first Number”; A
INPUT “Enter the second Number”; B
Sum = A + B
PRINT “The sum is”; Sum
GOTO AA
END

Looping Statement

Looping statement is the statement that executes one or more statements repeatedly in a
several number of times. In QBASIC there are three types of loops they are for, while and
do-while. When you need to execute a block of code several number of times you need to
use looping. Let’s discuss the major looping statements in QBASIC.

FOR……NEXT Statement

It is the fundamental looping statement in QBASIC. It provides a way to repeat a block
of statements over a predetermined number of times. The FOR…..NEXT loop is used
when we are required to perform repetitive tasks, such as to display addition of all values
between 100 to 200, display all prime numbers between 1 to 100, etc.
Syntax
For counter variable = <initial value>To <Ending Value> [step increment / decrement]
[statements]
[Exit For]
[statements]

Next

New Gateway to Computer Science Book -10 147

Practical Assignment

CLS CLS
FOR I = 1 to 10 FOR I = 1 to 10 STEP 2
PRINT I; PRINT I;
NEXT NEXT
END END
WHILE……WEND Statement
The WHILE…WEND loop is the fundamental loop statement in QBASIC. It provides a
way to repeat a block of statements, as long as the condition is true. It is used to perform
a repetitive task based on a condition. The condition usually results from a comparison
of two values, but it can be any expression that evaluates to a Boolean value (TRUE or
FALSE).
Syntax
WHILE (TEST CONDITION)
(Statements OF Loop)
WEND
Let’s observe the given table to understand the part of the syntax.

Part Description
TEST CONDITION It is a numeric or string expression that evaluates whether
the statement is TRUE or FALSE.
Statements OF Loop It is a set of one or more QBASIC statements.
WHILE Statement It always checks the condition before it begins the loop.
LOOP It continues till the condition remains TRUE.

Practical Assignment

REM a program to print series from 1 to 10
CLS
C=1
WHILE C <= 10
PRINT C
C=c+1
WEND
END

148 New Gateway to Computer Science Book -10

DO….WHILE LOOP Statement

A DO….WHILE loop is used when we want to repeat a set of statements as long as the
condition is true. The condition usually results from a comparison of two values, but it
can be any expression that evaluates to a Boolean value (TRUE or FALSE). The condition
may be checked at the beginning of the loop or at the end of the loop.
Syntax
DO WHILE (TEST CONDITION)
(Statements Of Loop)

LOOP

Let’s observe the given table to understand the part of the syntax

Part Description
TEST CONDITION
It is a numeric or string expression that evaluates whether the
Statement of Loop condition is TRUE or FALSE.

LOOP It is a set of one or more QBASIC statements.
• If the condition is TRUE, all statements in loop are executed

until the loop statement is encountered.
• Control then returns to the WHILE statement and condition is

again checked.
• If the condition is still TRUE, then the process is repeated.

If the condition is FALSE, then the loop statements are skipped
and the statement after LOOP statement is executed.

Practical Assignment

REM a program to print the series from 1 to 10
CLS
c=1
DO WHILE c <= 10
PRINT c
c=c+1
LOOP

END

DO….UNTIL LOOP Statement

A DO….UNTIL loop is used when you want to repeat a set of statements as long as the
condition is false. The condition may be checked at the beginning of the loop or at the
end of the loop.

New Gateway to Computer Science Book -10 149

Syntax
DO UNTIL (TEST CONDITION)
(Statements of Loops)
REPORT THIS AD

LOOP

Let’s observe the given table to understand the part of the syntax.

Part Description
TEST CONDITION
It is a numeric or string expression that evaluates
Statement of Loop whether the statement is TRUE or FALSE.

It is a set of one or more QBASIC statements.

Practical Assignment

REM a program to print the series from 1 to 10.
CLS
C=1
DO UNTIL C = 11 This number will not be displayed.
PRINT C
C=C+1
LOOP
END

EXIT Statement

The EXIT statement is used to terminate the loop based on certain criteria before the
expected number of iterations. When the EXIT statement is executed, the control jumps
to next statement immediately after the loop. We can use the EXIT statement in all types
of loops.

Syntax: EXIT DO / FOR

Practical Assignment

CLS
X=1
DO
prod = x* 5
IF prod >50 THEN EXIT DO
PRINT prod
X=X
LOOP WHILE X<=10

END

150 New Gateway to Computer Science Book -10


Click to View FlipBook Version