1 / 7

Random Access Files in VB

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 1'5'0' on diskLine" orientedVariable length, delimited by newline char (Java/C <br>')Text files are SequentialMust

cree
Download Presentation

Random Access Files in VB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    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 ‘1’‘5’‘0’ 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 <VB FixedString(20)> 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.

More Related