How can I store a binary file in my program, and output it to a file later?
Printable View
How can I store a binary file in my program, and output it to a file later?
Create a resource file. Start the Resource Editor from the tools menu (if you don't have it you have to first goto Add-Ins|Add-In Manager and start the VB6 Resource Editor add-in.).
Click the "Add Custom Resource..." button on the toolbar and browse to the file you want to add.
The resource is added with a new ID (probably 101) under a "CUSTOM" folder.
To write it back to disk use code simular to this:
Best regardsCode:Private Sub SaveIt(ByVal FileName As String)
Dim bArr() As Byte
Dim hFile As Integer
bArr = LoadResData(101, "CUSTOM")
hFile = FreeFile
Open FileName For Binary Access Write As #hFile
Put #hFile, , bArr
Close #hFile
End Sub
PS. Funny avitar your using! You had me fooled for a second.
is this you mean?
VB Code:
Dim buff As String Open "C:\Crsyb14.hlp" For Binary As #1 buff = String(LOF(1), Chr(0)) Get #1, 1, buff Close #1 Open "C:\Crsyb15.hlp" For Binary As #1 Put #1, 1, buff Close #1
regards,
The above will only read and write one byte. You shouldn't use strings either because they store two bytes for every character. Use a byte array instead.Quote:
Originally posted by Chris
is this you mean?
VB Code:
Dim buff As String Open "C:\Crsyb14.hlp" For Binary As #1 buff = String(LOF(1), Chr(0)) Get #1, 1, buff Close #1 Open "C:\Crsyb15.hlp" For Binary As #1 Put #1, 1, buff Close #1
regards,
That code worked for me.
hi, i just got back from a trip so i haven't tried out any of your code samples yet. thanks for replying. i'm just wondering if it is possible to store a byte array permanently in a program. Instead of loading it from a file every time I run a program, is it possible for it to be inside the program already? I'm asking this because if I give a program to other people, instead of sending them an executable and other data files, I just want to send them one file. again, thanks for helpinh.
Yes you can. Simply add them to a Resource File.