|
-
Mar 17th, 2005, 05:18 PM
#1
Thread Starter
Fanatic Member
Creating a file... [Resolved]
I'd like to take a bitmap and a text file, and turn them into one file. How can I compile them as such and then be able to read them afterwards?
Last edited by Nove; Mar 19th, 2005 at 12:24 AM.
-
Mar 17th, 2005, 05:32 PM
#2
Re: Creating a file...
The easiest way I've found to combine all kind of different information in a file is to use a PropertyBag. Of course only your application (or any that knows exactly how you've made it) will be able to read it.
This example takes a picture loaded into a PictureBox, named Picture1, and a text shown in a TextBox, named Text1, and save it to a supplied file name.
VB Code:
Public Sub SaveFile(ByVal sFileName As String)
Dim bArr() As Byte
Dim hFile As Integer
Dim pb As PropertyBag
Set pb = New PropertyBag
'Save the things in the property bag
pb.WriteProperty "Pic", Picture1.Picture, Nothing
pb.WriteProperty "Txt", Text1.Text, ""
'get the content
bArr = pb.Contents
'open the file and save
hFile = FreeFile
Open sFileName For Binary Access Write As #hFile
Put #hFile, , bArr
Close #hFile
End Sub
You can then use the following code to read the file.
VB Code:
Public Sub ReadFile(ByVal sFileName As String)
Dim hFile As Integer
Dim bArr() As Byte
Dim pb As PropertyBag
hFile = FreeFile
Open sFileName For Binary Access Read As #hFile
ReDim bArr(LOF(hFile) - 1)
Get #hFile, , bArr
Close #hFile
Set pb = New PropertyBag
pb.Contents = bArr
Picture1.Picture = pb.ReadProperty("Pic", Nothing)
Text1.Text = pb.ReadProperty("Txt", "")
End Sub
Of course you should add error trapping in the code above.
-
Mar 17th, 2005, 05:37 PM
#3
Thread Starter
Fanatic Member
Re: Creating a file...
Looks great, I'll try it out as soon as I can.
-
Mar 19th, 2005, 12:24 AM
#4
Thread Starter
Fanatic Member
Re: Creating a file... [Probably Resolved]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|