Binary append

F

Freddy Coal

Hi, I would like append strings to a binary file, but I don´t understand how
make that.

I try with:

FileOpen(1, Folder_Trabajo & "\Toma_Trazas.FC", OpenMode.Append,
OpenAccess.Write, OpenShare.Default)
FilePut(1, "My string") '<****** ERROR IN THIS LINE ******
FileClose(1)

My other question is how join two files in the same files.

Thanks in advance for any help.

Freddy Coal
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Freddy said:
Hi, I would like append strings to a binary file, but I don´t understand how
make that.

A character in .NET is a 16 unicode character, so a string can't be
written as bytes without first encoding it.

To encode the string, you can use the GetBytes method of the encoding
you want. Example:

Dim buffer As Byte() = Encoding.UTF8.GetBytes("My string")

Now you can write the bytes to the binary file.
I try with:

FileOpen(1, Folder_Trabajo & "\Toma_Trazas.FC", OpenMode.Append,
OpenAccess.Write, OpenShare.Default)
FilePut(1, "My string") '<****** ERROR IN THIS LINE ******
FileClose(1)

My other question is how join two files in the same files.

Either read one file and append to the other, or read both files and
write to a new file.
 
F

Freddy Coal

Göran, How can get the bytes of a short variable?.

The Short data have 2 bytes, how convert that to ASCII values?.

In the past I use something like:

Dim T_short As Short = 195
FileOpen(1, "C:\Temp.txt", OpenMode.Binary, OpenAccess.Write,
OpenShare.Default)

FilePut(1, T_short)

FileClose(1)

And I get a 2bytes file, the number 195 is represent for ASCII chars, I can
use the function chr(195), but that return me only 1 byte, and if the number
is more than 255, that command don´t work, I need the 2 bytes for represent
my number.

The question is, exist a function that put my new data (the short value) at
the end of my binary file?, remenber I need put my short data like a binary
(with 2 bytes), the same way that use Fileput(1, "Short variable").

Thanks.

Freddy Coal
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Freddy said:
Göran, How can get the bytes of a short variable?.

Use the BitConverter.GetBytes method. When you call it with a short
value, it returns an array of two bytes.
The Short data have 2 bytes, how convert that to ASCII values?.

An ASCII character can only hold 7 bits of information, so I don't think
that's what you want to do. Binary data is just bytes, not characters.
In the past I use something like:

Dim T_short As Short = 195
FileOpen(1, "C:\Temp.txt", OpenMode.Binary, OpenAccess.Write,
OpenShare.Default)

FilePut(1, T_short)

FileClose(1)

And I get a 2bytes file, the number 195 is represent for ASCII chars, I can
use the function chr(195), but that return me only 1 byte, and if the number
is more than 255, that command don´t work, I need the 2 bytes for represent
my number.

The question is, exist a function that put my new data (the short value) at
the end of my binary file?, remenber I need put my short data like a binary
(with 2 bytes), the same way that use Fileput(1, "Short variable").

Thanks.

Freddy Coal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top