creating a data file in vb, for a vb app

how do i create a file to hold sounds, pictures for a vb app, and load it in that app.

im writing a multiple choice questions prog and i want to create a data file that can contain sound files/pictue files is this possible? /how do i do it?
LVL 2
gerrymcdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

autCommented:
Create a resource file.
0
tsturmCommented:
Try out the HPI format used by the game Total Anilation. There's a VB 5 demo on using it at http://www.cws.org/~joed/ta/hpiutil.zip.
0
gerrymcdAuthor Commented:
tsturn!
i want to know how to do it with vb
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

gerrymcdAuthor Commented:
deat qut,
how do i create a resource file?
0
autCommented:
Steps:
1. Create a resource file (a text file, but with the extension ".rc"... Then in that file, enter a separate line for each item you want to include in the resource file.
 
The line will look like this:
IDENTIFIER      RESTYPE      C:\path\filename.ext
Make sure that "C:\path\filename.ext" actually points to the file you want to include.

* For "IDENTIFIER", put the number of the resource (alternatively, it can be a name)
* RESTYPE can be either:
    BITMAP
    ICON
    WAVE
    CURSOR
(as well as others, but you'll only need these ones)
A sample RC file would be:
100      ICON      C:\path\file1.ico
101      ICON      C:\path\file2.ico
201      BITMAP      C:\path\file1.bmp
302      WAVE      C:\path\file1.ico


2. Compile the resource file. You can do that using the resource compiler EXE file (RC.EXE). All you have to type is:
   RC myresfile.rc
You'll find the RC.EXE file on your VB CD, or on one of the Visual Studio CD's

3. Include the compiled resource file in your project.

4. You can then access the resources using:
LoadResPicture() function (for cursors, icons and pictures)
LoadResData() function (for binary data -- e.g. wave files)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VbmasterCommented:
You can store multiple files inside one file using simple Put statements. Something like this..

Dim ByteArray() As Byte

Open destfilename For Binary As #1

Open file1 For Binary As #2
ReDim ByteArray(LOF(2) - 1)
Get #2, , ByteArray
Put #1, , LOF(2)
Put #1, , ByteArray
Close #2

..
..

Open file9999... For Binary As #2
ReDim ByteArray(LOF(2) - 1)
Get #2, , ByteArray
Put #1, , LOF(2)
Put #1, , ByteArray
Close #2

Close #1


If you do this you can read back the info using Get statements like this (this example reads back the first file that was saved)..

Dim ByteArray() As Byte
Dim lValue As Long        <- to store filesize

Open destfilename For Binary As #1
Get #1, , lValue
ReDim ByteArray(lValue - 1)
Get #1, , ByteArray
Close #1


You will have to store the byte array to disk before you can use it, unless you use some 3rd party control that can handle byte arrays (= $$$). You store the byte array to a file with code like

Open filetemp For Binary As #1
Put #1, , ByteArray
Close #1


Then you can use the filetemp in your program, for example if it's a picture you can use code like "Picture1.Picture = LoadPicture(filetemp)" to show it in Picture1. When you're done with it just remove it from your disk.

Using this scheme will make your big file look something like this..

***********************************************
* how big is the next file? (Long value) *
* Byte Array containing information      *
**********************************************
..
..
***********************************************
* how big is the next file? (Long value) *
* Byte Array containing information      *
**********************************************
0
autCommented:
vbmaster: what you say is also true.

BUT

(a) The images/sounds will not be included within the EXE file. With resource files, everything is within the EXE, and they are loaded into memory as needed.

(b) If the programmer needs to modify a single file from the component files, the following has to be done:
    - Modify the file
    - Regenerate the large single file
    - Redefine the size of each file in the program
    - Recompile the EXE
Using the resource compiler, it become a lot easier.

(c) Reading the files cannot be done with built-in VB functions. The programmer will have to create his own functions to access the "big file"

(d) This will also mean creating code for writing, reading, and deleting temporary files

As you see, most of the above is unnecessary, if the programmer had initially used resource files...
0
VbmasterCommented:
Well, I would NOT recommend to do exactly what I wrote, but I drew up the ideas how to work. Of course you will need to do some works, I would probably add all the filesizes to the end of the big file instead of the start of every small file, this way all the filesizes can be read at the same time and if you know the filesizes you also know exactly where to start in the big file when you want to 'extract' a file.

Resource files are very good to work with... BUT if you read gerrymcd's question it sure sounds like he wants these big files outside the exe's..

"I'm writing a multiple choice questions prog and i want to create a data file that can contain sound files/pictue files is this possible?"

Let's say he uses resource files, then he would be stuck with the number of questions he made when he compiled the project, if he wants to add questions he would have to recompile the whole project.

And bigger executables means longer time to start and probably more memory is used. I do not know if it's true but I also have experienced that bigger executables also means a lot worse performance than using a small executable.

"(c) Reading the files cannot be done with built-in VB functions. The programmer will have to create his own functions to access the "big file""

Is everybody here afraid of acutal 'coding'? ;)
0
autCommented:
vbmaster:

"Is everybody here afraid of acutal 'coding'?"
;-))
Actually no, but I meant it from a performance standpoint...

As far as I know, resources from resource files are only loaded (and hence take up memory) when they are needed.

gerrymcd,
if you want to include a fixed set of files, go for a resource file. If you think you will be changing these files often, then go for vbmaster's idea, it's more expandable -- IMHO.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.