473,396 Members | 2,013 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,396 software developers and data experts.

Append to byte()

I need to append to a byte array in a maximum of 256 byte increments.

How??

dim x as fullbytearray()
dim y as windowbytearray()

'y gets it's bytes (256 or less)
need to
x=x & y
or x=x.append(y)

I can't find a way to do it.

Please help,

Shane
Nov 20 '05 #1
6 27426
Hello,

"SStory" <Th*******@TAKETHISSPAMBUSTEROUT.Softhome.net> schrieb:
I need to append to a byte array in a maximum of 256
byte increments.

How??

dim x as fullbytearray()
dim y as windowbytearray()

'y gets it's bytes (256 or less)
need to
x=x & y
or x=x.append(y)


What's 'fullbytearray' and 'windowbytearray'? You can use 'ReDim Preserve'
to change the size of an array and use 'Array.CopyTo' to copy the data into
the array. Notice that changing the size of an array is a costly process.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2
Hi SStory,

Did you know that ReDim Preserve is still available?

There's also Array.CopyTo (DestArray, Offset)

ReDim Preserve x (x.Length + y.Length)
y.CopyTo (x, x.Length)

Regards,
Fergus
Nov 20 '05 #3
"SStory" <Th*******@TAKETHISSPAMBUSTEROUT.Softhome.net> schrieb
I need to append to a byte array in a maximum of 256 byte
increments.

How??

dim x as fullbytearray()
dim y as windowbytearray()

'y gets it's bytes (256 or less)
need to
x=x & y
or x=x.append(y)

I can't find a way to do it.


Have a look at the shared methods System.Array.Copy and the instance methods
System.Array.CopyTo. In general, you can not change the size of an array.
You have to create a new one and copy whatever you want into it.
ReDim Preserve is one way to create a new array and copy the old one in the
new one.
--
Armin

Nov 20 '05 #4
SStory,
In addition to the others comments I posted the start of a ByteBuffer class
that functions very similar to the System.Text.StringBuffer class in that it
maintains a byte array internally allowing you to append byte arrays on the
end, expanding the internal array as needed.

http://groups.google.com/groups?q=By...phx.gbl&rnum=3

Hope this helps
Jay

"SStory" <Th*******@TAKETHISSPAMBUSTEROUT.Softhome.net> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
I need to append to a byte array in a maximum of 256 byte increments.

How??

dim x as fullbytearray()
dim y as windowbytearray()

'y gets it's bytes (256 or less)
need to
x=x & y
or x=x.append(y)

I can't find a way to do it.

Please help,

Shane

Nov 20 '05 #5
Great. I thought about that. Is preserve the best way or should I use the
array.copy stuff or what?

The idea is append should
create a new byte array
copy old data in first part and then copy data to be appended after then set
the internal buffer to the new one.

Is this right?
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
SStory,
In addition to the others comments I posted the start of a ByteBuffer class that functions very similar to the System.Text.StringBuffer class in that it maintains a byte array internally allowing you to append byte arrays on the end, expanding the internal array as needed.

http://groups.google.com/groups?q=By...phx.gbl&rnum=3
Hope this helps
Jay

"SStory" <Th*******@TAKETHISSPAMBUSTEROUT.Softhome.net> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
I need to append to a byte array in a maximum of 256 byte increments.

How??

dim x as fullbytearray()
dim y as windowbytearray()

'y gets it's bytes (256 or less)
need to
x=x & y
or x=x.append(y)

I can't find a way to do it.

Please help,

Shane


Nov 20 '05 #6
Hi SStory,

ReDim Preserve is implemented as calls to the .NET Framework proper. This
applies to much of the VB legacy syntax. In practice, unless you're writing
'inner loop' code, the difference in speed is not outweighed, for most
developers, by the ease of developing with something familiar.

Having a C background and therefore being keen on C#, I tend to use the
Framework as much as possible. In part this allows me to universally apply any
new stuff that I learn. It's a very bendy rule, however, especially for
strings. I would probably use ReDim Preserve myself. ReDim Preserve uses
Array.Copy internally.

I gave an incorrect example. The code should have been.

Dim x(4) As byte '5 = 0..4
Dim y(3) As byte '4 = 0..3
: : :
Dim xL As Integer = x.Length
ReDim Preserve x (xL + y.Length - 1) '9 = 0..8
y.CopyTo (x, xL)

I forgot that the value in Dim and ReDim is <not> the number of items but
the upper index. [And I'm sure I'll forget some more times :-)]

This then leads to:
Function ArrayConcat (x() As Byte, y() As Byte) As Byte()
Dim xL As Integer = x.Length
ReDim Preserve x (xL + y.Length - 1)
y.CopyTo (x, xL)
Return x
End Function
or
Function ArrayConcat (x() As Byte, y() As Byte) As Byte()
Dim newx (x.Length + y.Length - 1) As Byte()
x.CopyTo (newx, 0)
y.CopyTo (newx, x.Length)
Return newx
End Function

Regards,
Fergus
Nov 20 '05 #7

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

Similar topics

19
by: John Keeling | last post by:
Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows:...
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
1
by: Access | last post by:
Here is my function to change a users permission level in the database. This relates to an Access database secured using Access security. This function is called if the end user changes a staff...
14
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!
5
by: Eric | last post by:
Is there a class that will allow me to append a byte to another? The data that I have is binary so StringBuilder will not work.
1
by: Pucca | last post by:
I have a string, "-1608" that I need to append to a byte variable. How can I convert the string to a byte so I can append it? thanks. -- Thanks.
3
by: Freddy Coal | last post by:
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,...
3
by: jaleel | last post by:
Hi I have got two binary files.(extension is .atf (some IBM stuff)). Dont know the exact details.I think the files are something like PDF files.i just want to append two files. I am thinking...
4
by: BerlinBrown | last post by:
Is it possible to just build the binary content of a zip file. I want to create the content in memory (e.g. return binary data) and then get those byte strings representing the zip file? Is that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.