Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picture file problem / Binary file read

Status
Not open for further replies.

kodr

Programmer
Dec 4, 2003
368
Could someone help me with this code?

Code:
        SavePicture picTemp.Image, App.Path & "\tmpout.bmp"
        DoEvents
        Open App.Path & "\tmpout.bmp" For Binary Access Read As #7
            Do While Not EOF(7)
                Get #7, , sFileDataTemp
                sFileDataOut = sFileDataOut & sFileDataTemp
            Loop
            lFileLen = Len(sFileDataOut)
        Close #7
[\code]

What's happening is, the "Get #7, , sFileDataTemp" line is not returning any data, when I step through my code, it show's sFileDataTemp = "".  I've created a temp program that does just the above, and it seems to work fine.  All the variables are Dim'd as local strings, except for lFileLen which is a local Long.

I've also verified that the save portion is correct, it generates a bitmap that I can open with any editor just fine.

Thanks
 
kodr,

<<Get #7, , sFileDataTemp>>

I'm pretty sure that your code above will retreive a number of bytes from the file equal to the length of the variable (sFileDataTemp). If the variable has zero length (a blank string) no bytes will be returned in it.

Try Diming sFileDataTemp as a fixed length string as in;

Dim sFileDataString * 20

or precede the line containing Get with;

sFileDataTemp = space$(20)

and check the contents again.

My use of 20 is just an arbitary length example, you may consider a length of LOF(7) which should allow you to Get the whole file into a string in one shot.

Hugh,

Ps. Do checkout the Freefile function in VB help and stop using literal file numbers.
 
Thanks for the info. I see what you mean about the length of the string, that makes sense.

I usually use Freefile, but I used the literal file number just to test my app, I thought it might have been the trouble.

This gives me a place to start, thanks.
 
kodr,

If all you want is lFileLen, you should checkout VB's FileLen function.

Hugh,
 
Yeah, thanks. I'm actually manipulating that value farther down the program.

Redim'ing sFileDataTemp(LOF(7)) made all the difference.

I experimented by making the array different sizes, and you could really tell the difference in the speed of the program, grabbing all the data at once is MUCH faster then byte by byte.

The bit of code above is just part of the 'test' app that I was working on, to work out bugs on the actual program. I'll clean up things like Freefile and LOF when I integrate it into my actual program.
 
I noticed that the string sFileDataTemp didn't really work out, I had to make it a byte array. I was getting flaky results as a string, the file size when I saved it was too large, and contained lots of white space.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top