From: Helmut Meukel on
"Jeff Caton" <j.caton(a)gmailnotspam.com> schrieb im Newsbeitrag
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.


Jeff,

you will get better answers if you provide some code how you access
your data files.
Do you use the file system object or the open statement?
Do you use Input, Line Input or Get?
What data types do you store in your files?
YOU know your code and your data, but we don't.
And we aren't mindreaders either.

Helmut.

From: Larry Serflaten on

"Jeff Caton" <j.caton(a)gmailnotspam.com> wrote
> 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.

Yes, it is 'possible' that an old file might have bytes that appear to be a
header, which is why you might consider changing the file extension.
That way you can know from the extension whether to expect a header
or not.

As far as putting strings into a header, do you realize that to a computer
everything is a number? Letters are numbers when stored in memory, as
are picture files, sound files, rich text files, HTML files, and everything else.
Every byte in memory can only hold a value from 0 to 255, likewise for
every byte in a file. To see for yourself, open a file in binary, read it into
an array, and inspect the values. Every file you open will be some group
of numbers.

The point is; you put specific numbers into the header, and expect to find
those same numbers when you read the file.

For a simple example, paste the code below to a new form and run it.

LFS


Private Sub Form_Load()
Dim msg(0 To 13) As Byte

msg(0) = 72: msg(2) = 105
msg(4) = 32: msg(6) = 74
msg(8) = 101: msg(10) = 102
msg(12) = 102

MsgBox msg
End Sub


From: Mayayana on
You might find it useful to look at how different
files are constructed. Usually there's some kind
of header, followed by 1 or more defined sections.
For instance, with a BMP file the first two bytes
of the header are always "BM" (Hex: 42 4D
Decimal: 66 77) The next 4 bytes indicate the file
size. Etc.

If you need to store info in the file header you
could use a UDT. Use a byte array to store an
ANSI string. If the string is variable in length then
you can include a value that indicates the offset
into the file of the actual file content.

So, say you want to ID your file by having the
first 3 bytes "NNN". A very simple header might
go like the following:

Type Header
ID as long
LenInfo as long 'set to number of bytes in Info member.
Offset as long ' beginning point of actual file content.
Info as Byte() 'store string data here.
End Type

ID = 7631988 ' N is 116. 116 + (116 x 256) + (116 X 65536) = 7631988.
' If you write a long of 7631988 that will translate to
the
'first 4 bytes being 4E 4E 4E 00. In a hex editor you'll see "NNN".

Offset would just be 12 + number of bytes in Info, but
I put that in there as an example. In a more complex header
a file offset value might be necessary.


| 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.