SD & D Sequential Files

12
Sequential Files

Transcript of SD & D Sequential Files

Sequential Files

Sequential FilesA sequential file is a collection of data items stored on a

backing storage device

Data items are stored in the file one after the other

To access a specific data item, we must first read through all of the preceding data items (in sequence) until we reach the data item we want

Sequential files use an end-of-file (EOF) marker to indicate that the end of the file has been reached

Sequential Files

File OperationsThere are a number of file operations which can be performed on a sequential file. We are only interested in the following:OpenCreateCloseReadWriteDelete

OpenPseudocode:OPEN Filename

LiveCode:

CreatePseudocode:CREATE Filename

LiveCode:

(opens the file, if it doesn’t exist then LiveCode will create it)

ClosePseudocode:CLOSE Filename

LiveCode:

ReadPseudocode:

OPEN FilenameREPEAT UNTIL EOF

READ next record from Filename into field / arrayEND REPEATCLOSE Filename

ReadLiveCode:

WritePseudocode:

OPEN FilenameREPEAT UNTIL EOF

WRITE next field/array element to FilenameEND REPEATCLOSE Filename

WriteLiveCode:

DeletePseudocode:DELETE Filename

LiveCode: