From: Jeff Caton on
That is exactely what I want to do. But I am afraid to mess anything up.
I am not sure how I should first PUT the bytes and then READING and
REMOVING it.
Do I have to take the LOF(iFile)-iLenOfHeader bytes and write them to a
new file?
Any code would of course be great.

> "Jeff Caton"<j.caton(a)gmailnotspam.com> wrote
>> I would like to attach a custom "header" to a file so that I can savely
>> identify which format is it (it's my own custom format). Can somebody
>> please tell me how to do that?
>> I don't want to use the extension only because I have different versions
>> of my file format and I need to check which one is actually is.
>
> You say its your own custom format. That means you've designed what
> goes into the file, how it's stored, etc. Just reserve a few bytes at the start
> to let you store your version information....
>
> LFS
>
>

From: Larry Serflaten on

"Jeff Caton" <j.caton(a)gmailnotspam.com> wrote
> That is exactely what I want to do. But I am afraid to mess anything up.
> I am not sure how I should first PUT the bytes and then READING and
> REMOVING it.
> Do I have to take the LOF(iFile)-iLenOfHeader bytes and write them to a
> new file?
> Any code would of course be great.

Its a custom design, you can do it any way you want, any way you feel
comfortable with.

If it were me, I'd probably use a fixed length Byte array and read that
from the file to test for a specific identifier.

Dim head(8) As Byte
Dim data() as Byte

' To write it out:

(Open filename for binary as fileNumber)
Put #fileNumber, , head
Put #fileNumber, , data
(Close file)

' To read it in:

(Open filename for binary as fileNumber)
Get #fileNumber, , head
Get #fileNumber, , data
(Close file)

What you put in those 8 bytes (more or less as desired) is entirely
up to you. You can stuff it with whatever you need to identify the
file, and/or version number.

Try it a few times, to see if it will work for you. If you have problems,
post back (with your test code example...)

LFS


From: Nobody on
Besides what Larry suggested, make sure that you truncate the file to 0 or
delete it if it already exists, in case the existing file is longer than
what you are trying to write, otherwise the file would remain at the old
length, with extra bytes at the end. This is the case when using "Open ...
For Binary".

Before writing to the file, you can delete the existing file using Kill
statement, or truncate it to 0 using "Open ... For Output". Unfortunately
you can't use Put statement with files opened with "For Output", so you have
to close it, then reopen it "For Binary". "Get statement" is likewise can't
be used with files opened "For Input". So Get/Put can only be used with
Binary/Random file modes.


From: Jeff Caton on
My question would be how I can put strings into the header because I
don't think that choosing a number is a wise idea. The file may be in an
old format (without a header) and its contents (the first bytes of the
file) may just be exactely this header.
Unprobable, but I think in the computer world anything that can happen
will happen.

Maybe it's simple for you, but these string to byte to hex to integer to
long conversions really are not something funny to me.
From: Jeff Johnson on
"Jeff Caton" <j.caton(a)gmailnotspam.com> wrote in message
news:eITfEQu6KHA.5476(a)TK2MSFTNGP06.phx.gbl...

> My question would be how I can put strings into the header because I don't
> think that choosing a number is a wise idea. The file may be in an old
> format (without a header) and its contents (the first bytes of the file)
> may just be exactely this header.
> Unprobable, but I think in the computer world anything that can happen
> will happen.
>
> Maybe it's simple for you, but these string to byte to hex to integer to
> long conversions really are not something funny to me.

I think you're overcomplicating this in your mind, but to be sure, could you
give us a sample of what the file header looks like now and a sample of what
you'd LIKE it to look like (whether or not you'll actually make it look like
that or not)?