Text Files
Text files are also sometimes known as sequential files
Accessing Files
There are three ways you can access file:
Sequential - This allows reading and writing of individual characters or entire lines. You can start at the beginning and read forwards until you reach the end.
Random - This allows you to read and write record that all have the same length.
Binary - This allows you to read and write to specific byte positions within a file.
Private Function FileNameOnly(sFullPath As String) As String
Dim I As Integer
Dim length As Integer
Dim temp As String
Length = Len(sFullPath)
temp = ""
For I = length to 1 Step -1
If Mid(sFullPath,I,1) = Application.PathSeparator Then
FileNameOnly = temp
Exit Function
End If
temp = Mid(sFullPath,I,1) & temp
Next i
FileNameOnly = sFullPath
End Function
Title
The Dir function attempts to match its input argument against existing files.
This function can be used with valid wild cards under Windows for matches such as "*.xls".
If it finds a match, it returns the first match found and can be called again without an input argument to get subsequent matches.
Does a file exist
If Dir("C:\Temp.xls") <> "" Then
'then the file exists
End If
Dim sFolderPath As String
If Dir(sFolderPath, vbDirectory) <> "" Then 'folder path exists
Else
'folder path does not exist
End If
Text Streams
There are three ways to access a file
Sequential
Random
Binary
Sequential Access
This methods starts reading from the start and reads a line at a time
The Open statement is used to open your file.
Additional
You can specify the exact position in a file using the Seek() function.
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext