View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
moon[_7_] moon[_7_] is offline
external usenet poster
 
Posts: 53
Default Cleaning some blob data


"Andy Kessel" schreef in bericht
oups.com...
I need to do a little file manipulation with VBA

I am pulling blob data out of ms sql server using text copy, the files
are jpeg files that have had tags added to the front of the file, and
of course could be fairly big.

I know that the actual jpeg begins with a particular 4 characters, so I
could identify how many characters into the file i have the real file
starting.

Now if this was a string, I would just use instr to find the start and
right(x$,len(x$)-instr(1,x$,instr$)) to get the data. But this is too
damn big for that method.

Any suggestions? Do I have to do this character by character? if so I
could use a little help with how.




Open the file in binary mode and read a group of 4 bytes, instead of
character by character. U can store 4 bytes in a byte array, rather than a
string.

Public Sub ReadJPGHeader()
Dim FileNum As Integer
Dim FileName As String
Dim FileHeader(3) As Byte
FileNum = FreeFile
FileName = "C:\TEST.JPG"
Open FileName For Binary Access Read As FileNum
Get FileNum, , FileHeader
Close FileNum
'MsgBox Hex(FileHeader(0))
'MsgBox Hex(FileHeader(1))
'etc.
End Sub


But after all it's way faster to do this in C++, so a .dll that does the
dirty work, called by VBA.