VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



An easy way to read and write data to/from a file using binary mode. One function, no other require

by David M. Lewis (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 19th May 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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




'(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


Download this snippet    Add to My Saved Code

An easy way to read and write data to/from a file using binary mode. One function, no other require Comments

No comments have been posted about An easy way to read and write data to/from a file using binary mode. One function, no other require. Why not be the first to post a comment about An easy way to read and write data to/from a file using binary mode. One function, no other require.

Post your comment

Subject:
Message:
0/1000 characters