Saving and Accessing Data
Two general ways to save data To an established file format, like MS Access or Excel. That is the most common way. To a file that you define (dat, txt, etc.): Sequential Random Binary
File differences Sequential Read/Write the WHOLE file Random Read/Write any Record Binary Read/Write any Byte
Opening Files Read Write Both Open “theFile.txt” as #1 Now refer to theFile.txt as #1 The # is the “channel” of the file You can find a FreeFile.
You open with the following modes: Append Binary Output Random Adds to end of sequential file Write/Read individual Bytes Write/Overright sequential file Write to specific Records Random is the Default Open “myFile.txt” for Random as #3
Managing Multiple Users Access Restriction Write Read Write Read LockType Shared Lock Read Lock Write Lock Read Write Open "C:\Random.txt" For Random Access Read Write Shared As #intFile Len = 5 Book is not clear on Access. These are needed when multiple users are involved to maintain file integrity.
Length -- Len Necessary with random files to let the computer know how far to look for the next record. RECORD – One “line” or set of information. Examples: Each recipe in a cookbook; Each entry in an address book.
Input/Output Choices To File From File Sequential (Append, Input, Output) Print # Write # Read # Random Put # Get # Put #7, recordNum, Variable
Delimeters Delimeters are characters that indicate the end of a “column” or “field” A column or field is one variable in a record. Kevin, Harville, Instructor, 123-45-6789 Joe, Jones, Dog Catcher, 987-65-4321
Record Lengths Kevin Harville Instructor Joe Jones Dog Catcher Establishing data lengths helps the computer know where to look for the information
Data Types Data Types are like a master variable with sub-variables. Employee.Age Employee.FirstName Employee.LastName Employee.SSN
Data Types Declare in Modules Type Employee strFName As String * 10 strLName As String * 16 strSSN As String * 12 End Type ----------------------------------- Dim Worker(100) As Employee Worker(x).strFName=strInputName Worker(x).strLName=strInputLName Worker(x).strSSN=txtSSN.Text
File Controls File List Box Drive List Box Directory List Box You need to program functionality in these or the common dialog box to manually access files
File Commands Chdrive ChDir Kill MkDir RmDir Dir
Changing Usual place to responde to changes is in the Change event of the directory, file, or drive controls. ChDrive drvDisk.Drive ChDir dirDirect.Path FilFiles.Pattern= “*.txt; *.htm”