473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Binary append

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
Apr 25 '07 #1
3 4797
Freddy Coal wrote:
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.
Thanks in advance for any help.

Freddy Coal


--
Göran Andersson
_____
http://www.guffa.com
Apr 25 '07 #2
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
"Göran Andersson" <gu***@guffa.comwrote in message
news:e0**************@TK2MSFTNGP02.phx.gbl...
Freddy Coal wrote:
>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.
>Thanks in advance for any help.

Freddy Coal


--
Göran Andersson
_____
http://www.guffa.com

Apr 25 '07 #3
Freddy Coal wrote:
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
"Göran Andersson" <gu***@guffa.comwrote in message
news:e0**************@TK2MSFTNGP02.phx.gbl...
>Freddy Coal wrote:
>>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.
>>Thanks in advance for any help.

Freddy Coal

--
Göran Andersson
_____
http://www.guffa.com


--
Göran Andersson
_____
http://www.guffa.com
Apr 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bix | last post by:
As this is my very first post, I'd like to give thanks to all who support this with their help. Hopefully, this question hasn't been answered (too many times) before... If anyone could explain...
13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
3
by: Rune Froysa | last post by:
Trying something like:: import xmlrpclib svr = xmlrpclib.Server("http://127.0.0.1:8000") svr.test("\x1btest") Failes on the server with:: xml.parsers.expat.ExpatError: not well-formed (invalid...
2
by: vbMark | last post by:
Greetings, This seems like it should be simple but I can't figure out how to do this. I just want to append binary file 2 on to the end of binary file 1. Sample code please? Thanks!
13
by: HNT20 | last post by:
Hello All i am new to python language. i am working on a gnuradio project where it uses python as the primary programming language. i am trying to convert a message, text, or numbers into binary...
1
by: AlekseyUS | last post by:
Hi, I'm a little stuck, I basically need to copy all the information within a specific file in Temp and append it to a file in another location. I'm not having any problems with smaller size...
23
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
1
by: Gert Conradie | last post by:
The following code can uplaod text files. When i upload a binary file it fail. I might be: 1) using the wrong Encoding 2) will have to System.Convert.ToBase64String the content of the binary...
5
by: Canned | last post by:
Hi, I'm trying to write a class that can convert ascii to binary and vice versa. I write my class based on this function I've found on internet That works perfectly, but when I try to implement...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.