An easy way to read and write data to/from a file using binary mode. One function, no other require
An easy way to read and write data to/from a file using binary mode. One function, no other requirements.
Rate An easy way to read and write data to/from a file using binary mode. One function, no other require
(2(2 Vote))
'(c) David M. Lewis, 2007 [email protected]
'This source code is free to use for non-profit purposes. Give me credits if you use it please.
'Binary access file IO function. Provides an easy and universal method of reading and writing data to files.
'fname - full filename with path.
'Wmode - TRUE if writing, FALSE if reading.
'Wdata - Data to be written. ALSO sets read string length, so if you're reading,
'the send a string with the length you want read. Fill the string with anything.
'Soffset - Start offset in file.
'On error, the string "ERROR" is returned. Otherwise the same data is returned.
'Note there's no error trapping included. Make sure you can access the file first.
Dim ff As Integer
Dim tdata As String
On Error GoTo fileerr
ff = FreeFile
tdata = Wdata
BinIO = "ERROR"
If Not UCase(Wdata) = "WRITE" And UCase(Wdata) = "READ" Then GoTo fileerr
Open fname For Binary As #ff Len = Len(tdata)
If UCase(Wmode) = "WRITE" Then
'We write!
Put #ff, Soffset, tdata
BinIO = tdata
Else
'We Read!
Get #ff, Soffset, tdata
BinIO = tdata
MsgBox tdata
End If
Exit Function
fileerr:
tdata = "ERROR"
End Function
An easy way to read and write data to/from a file using binary mode. One function, no other require Comments
No comments yet — be the first to post one!
Post a Comment