VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Opens a file for binary read or write. Gets amount of data into whole or partial buffers. Good for

by Deano Splamoni (15 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 31st July 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Opens a file for binary read or write. Gets amount of data into whole or partial buffers. Good for file transfer or packet sending programs!

API Declarations


'change the filenames and buffersize if wanted

Rate Opens a file for binary read or write. Gets amount of data into whole or partial buffers. Good for



'=~=~=~=~=~=~=~=~=~=~
Private Sub cmd1_Click()
Dim buffer$             'Declares the buffer
'Opens the file so binary can be take from the file
Open App.Path & "\file1.exe" For Binary Access Read As #1
'Puts a space per byte for every byte of the opened file
buffer$ = Space(LOF(1))
'Gets the amount of binary data from the file that the buffer can hold
Get #1, , buffer$
'Closes file
Close #1
'Opens a new or exising file so binary can be put into the file
Open App.Path & "\file2.exe" For Binary Access Write As #1
'Puts the data in the buffer, into the file
Put #1, , buffer$
'closes the file
Close #1
End Sub

'USING PARTIAL BUFFER
'=~=~=~=~=~=~=~=~=~=~

Private Sub cmd1_Click()
Dim buffer$             'Declares the buffer
    'Declares buffersize, the size of the buffer
    'and bufferleft, the amount of data left to get
Dim buffersize As Long, bufferleft As Long
    'choose an amount of data to get from the file
buffersize = 1024
    'Opens the file so binary can be take from the file
Open App.Path & "\file1.exe" For Binary Access Read As #1
    'Opens a new or exising file so binary can be put into the file
Open App.Path & "\file2.exe" For Binary Access Write As #2
    'sets the amount of data left as all the bytes in the file
bufferleft = LOF(1)
retake:
    'Puts an amount of spaces the buffersize is
buffer$ = Space(buffersize)
    'Gets the amount of binary data from the file that the buffer can hold
Get #1, , buffer$
    'Puts the data in the buffer, into the file
Put #2, , buffer$
bufferleft = bufferleft - buffersize
If bufferleft = 0 Then GoTo Done:
If bufferleft < buffersize Then buffersize = bufferleft
GoTo retake:
Done:
    'closes the files
Close #1
Close #2
MsgBox "done"
End Sub


Download this snippet    Add to My Saved Code

Opens a file for binary read or write. Gets amount of data into whole or partial buffers. Good for Comments

No comments have been posted about Opens a file for binary read or write. Gets amount of data into whole or partial buffers. Good for . Why not be the first to post a comment about Opens a file for binary read or write. Gets amount of data into whole or partial buffers. Good for .

Post your comment

Subject:
Message:
0/1000 characters