Random Access Files in VB'NET - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Random Access Files in VB'NET

Description:

In-memory data is converted to ASCII characters upon output. ... Can freely overwrite/edit existing record w/o disturbing others (fixed length) ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 8
Provided by: cisUso
Category:

less

Transcript and Presenter's Notes

Title: Random Access Files in VB'NET


1
Random Access Files in VB.NET
  • ITE285
  • R. Johnson

2
Text Files Recap
  • Read/written with StreamReader and Writer.
    Object-oriented syntax.
  • In-memory data is converted to ASCII characters
    upon output.
  • Integer 150 becomes digits 150 on disk
  • Line oriented
  • Variable length, delimited by newline char
    (Java/C \n)
  • Text files are Sequential
  • Must start reading at beginning.
  • Cannot easily edit data in middle of the file.

3
Random Access Files
  • Record based.
  • Fixed length, so no delimiting character.
  • In-memory record (a structure variable) is mapped
    to/from disk. Must fix lengths of string fields!
  • Data stored in raw binary form.
  • In-memory bit pattern for numbers copied to disk
    as-is rather than digits translated to ASCII
    chars.
  • Record Number and fixed length allows direct
    access to arbitrary position.
  • Byte offset of desired record in file
    (Record -1) x length of record in bytes

4
Comparison
5
Tasks and Syntax
  • FileOpen associates file number with file and
    sets I/O modes needs record length!
  • FIlePut (filenum, recordvar, recnum)
  • FileGet (filenum, recordvar, recnum)
  • FileClose
  • records in existing file? recs length of
    file (in bytes) / rec length
  • Add new record at position one past last record.
  • Can freely overwrite/edit existing record w/o
    disturbing others (fixed length).

6
Record Structure
  • Define a VB Structure data type for in-memory
    record.
  • Strings MUST be made fixed length so overall
    record size is fixed ltVB FixedString(20)gt
    Public name As String
  • Put definition at form-level, or in module for
    global use in bigger app.

7
More
  • This is the old, low-level (but easy!) way to do
    it.
  • .NET uses BinaryReader and Writer to do what is
    called serialization of objects, saving their
    state to a file (or XML to be sent over internet)
  • You will most likely use ADO.NET, tying VB to
    external databases, for real world data storage.
Write a Comment
User Comments (0)
About PowerShow.com