DATA PROCESSING
WEEK 9 NOTE
BASIC OPERATIONS ON COMPUTER FILES
1. FILE CREATION: Files are created by using a particular application package to enter (type) the
content of the file and saving it by giving it a name.
2. FILE DELETION: we delete a file when it is no longer useful.
3. FILE RETRIEVAL: The file is brought out from where it is stored/saved for further processing.
4. FILE COPY: This is a process of making duplicate copies of a file.
5. FILE VIEW: We view a file by using an application with which it was created to open it so as to
see its contents.
6. UPDATE: Updating a file means changing some or all of its contents.
7. OPEN: A file is opened when its contents are displayed on the screen (monitor).
8. CLOSE: A file is closed when we finish the processing tasks on it or we want to stop till next time.
CREATING AND ACCESSING SEQUENTIAL FILES IN BASIC
The following statements and functions are used with sequential files in BASIC programming language:
CLOSE LOF
EOF OPEN
INPUT# PRINT#
LINE INPUT# PRINT#USING
LOC UNLOCK
LOCK WRITE#
The following program steps are required to create a sequential file and access the data in a file.
1. Open the file in output (O) mode. The current program will use this file first for output:
Open “0”, #1, “filename”.
2. Write data to the file using the PRINT# or WRITE# statement:
PRINT#1,A$
PRINT#1,B$
PRINT#1,C$
3. To access the data in the file, you must close the file and reopen it in input (I) mode:
CLOSE#1
OPEN “1”,#1, “filename”
4. Use the INPUT# or LINE INPUT# statement to read data from the sequential file into the
program:
INPUT#1,X$,Y$,Z$
EXAMPLE 1
10 OPEN “0”,#1, “DATA”
20 INPUT “NAME”;N$
30 IF N$= “DONE” THEN END
40 INPUT “DEPARTMENT”;H$
50 INPUT “DATE HIRED”;H$
60 PRINT#1,N$;”, “D$”,H$
70 PRINT:GOTO 20
RUN
NAME? IGOCHE ANTHONY
DEPARTMENT? AUDIO/ VISUAL AIDS
DATE HIRED? 01/12/80
NAME? MALLAM UMAR
DEPARTMENT? RESEARCH
DATE HIRED? 12/03/65
OK
ACCESSING A SEQUENTIAL FILE
The program in Example 2 accesses the file data, created in the program in Example 1, and
displays the name of everyone hired in 1978.
EXAMPLE 2
10 OPEN “I”,#1,“DATA”
20 INPUT#1,N$,D$,H$
30 IF RIGHT$(H$2)= “78” THEN PRINT N$
40 GOTO 20
50 CLOSE #1
RUN
IGOCHE ANTHONY
SUPER MANN
Input past end in 20
OK
The program in Example 2 reads, sequentially, every item in the file. When all the data has
been read, line 20 causes an “Input past end” error. To avoid this error, insert line 15, which
uses the EOF function to test for end of file:
15 IF EOF(1) then end
And change line 40 to GOTO 15
ADDING DATA TO A SEQUENTIAL FILE
When a sequential file is opened in O mode, the current contents are destroyed. To add data to
an existing file without destroying its contents, open the file in append (A) mode.
The program in Example 3 can be used to create or to add onto a file called names. This
program illustrates the use of LINE INPUT. LINE INPUT will read in characters until it sees a
carriage return indicator or until it has read 255 characters. It does not stop at quotation marks
or commas.
EXAMPLE 3
10 ON ERROR GOTO 2000
20 OPEN “A”, #1, “NAME”
110 REM ADD NEW ENTRIES TO FILE
120 INPUT “NAME”; N$
130 IF N$= “” THEN 200 CARRIAGE RETURN EXITS INPUT LOOP
140 LINE INPUT “ADDRESS?”; A$
150 LINE INPUT “BIRTHDAY?”; B$
160 PRINT#1, N$
170 PRINT#1, A$
180 PRINT#1, B$
190 PRINT: GOTO 120
200 CLOSE#1
2000 ON ERROR GOTO 0
In lines 10 and 2000, the ON ERROR GOTO statement is being used. This statement enables error
trapping and specifies the first line (2000) of the error handling subroutine. Line 10 enables the error
handling routine. Line 2000 disables the error handling routine and is the point where BASIC branches to
print the error messages.
FILE INSECURITY AND ITS EFFECT
A file and its contents may be lost if care in not taken. The following can cause file insecurity: virus
attack, careless deletion of files, hardware failure or malfunctioning, overwriting, etc. A virus is a
malicious program that affects the computer and its contents. It causes the computer to be slow or
destroy the files in the computer. the major effect of file insecurity is data loss with its attendant
consequences on the individual and/or organization.
METHODS OF FILE SECURITY
The methods of file security are as follows:
1. USE OF BACKUPS: A backup is to make a copy of computer data to keep in case anything goes
wrong with the original. This can be done by saving the file in a secondary storage device like
CD, flash, DVD, etc.
2. USE OF ANTIVIRUS: An antivirus is a software that prevents virus attacks on computers. You
should install an antivirus program in your computer to ensure the security of your computer
files.
3. PASSWORD: A password is a sequence of characters that must be keyed in correctly to gain
access to a computer or a program in the computer. your computer should be password
protected to prevent unauthorized access to them.
4. PROPER LABELLING OF STORAGE DEVICES: Labelling of storage devices like diskette, CDs, DVD,
etc., helps in proper identification of computer files.
DIFFERENCES BETWEEN COMPUTER FILES AND MANUAL FILES
COMPUTER FILES MANUAL FILES
1. More secured Less secured
2. Fast to access Slow to access especially when there is large
number of files to access from
3. Less laborious to access More laborious
4. More reliable Less reliable
5. Files can be attacked by virus and Files can be attacked by rodents, termites,
worms cockroaches, fire, etc.
6. Files can be easily and neatly Cannot be easily and neatly modified.
modified
7. Not visible Visible
LIMITATIONS OF COMPUTER FILES
The following are limitations of computer files:
1. EXPENSIVE: Money is needed to buy and maintain a computer system.
2. IRREGULAR POWER SUPPLY: Accessing computer files is not possible if there is no source of
power from electricity-generating set, rechargeable battery, uninterrupted power supply
(UPS) or solar energy.
3. VIRUS ATTACK: This can limit the use of computer files.