<p>I have a class with a public array of bytes. Lets say its</p>

<pre><code>Public myBuff as byte()
</code></pre>

<p>Events within the class get chunks of data in byte array. How do i tell the event code to stick the get chunk on the end? Lets say</p>

<pre><code>Private Sub GetChunk
  Dim chunk as byte
  '... get stuff in chunk
  Me.myBuff += chunk '(stick chunk on end of public array)
End sub
</code></pre>

<p>Or am I totally missing the point?</p>

[{'answer_id': 77390, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 1, 'selected': False, 'text': '<p>if i remember right, in vb you want to redim with preserve to grow an array.</p>\n'}, {'answer_id': 77402, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>You'll be constantly using the ReDim keyword, which is <em>extremely</em> inefficient.</p>\n\n<p>Are you using .Net?  If so, consider using a System.Collections.Generic.List(Of Byte) instead.  You can use it's .AddRange() method to append your bytes, and it's .ToArray() method to get an array back out if you really need one.</p>\n"}, {'answer_id': 77405, 'author': 'Sam', 'author_id': 9406, 'author_profile': 'https://Stackoverflow.com/users/9406', 'pm_score': 0, 'selected': False, 'text': "<p>Your question doesn't seem to be very clear. You should probably not have the array of bytes as public. It should probably be private and you should provide a set of public functions that allow users of the class to perform operations against the array.</p>\n"}, {'answer_id': 77449, 'author': 'David J. Sokol', 'author_id': 1390, 'author_profile': 'https://Stackoverflow.com/users/1390', 'pm_score': 0, 'selected': False, 'text': '<p>I think you might be looking for something other then an array.  If you are trying to gradually extend the amount of data frequently, you should use a dynamic data structure such as<code>ArrayList</code>.  This has an <code>Add</code> method which adds the specific object or value to the array without concerns for space.  It also has a nifty <code>ToArray()</code> method that you can use.</p>\n\n<p>If you are trying to use an array for specific reasons (performance, I guess), use <code>ReDim Preserve array(newSize)</code>.</p>\n'}, {'answer_id': 78059, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>If the array is small, and new data is infrequently added, an easy way would be to:</p>\n\n<pre><code>public BufferSize as long 'or you can just use Ubound(mybuff), I prefer a tracker var tho\npublic MyBuff\n\nprivate sub GetChunk()\ndim chunk as byte\n'get stuff\nBufferSize=BufferSize+1\n\nredim preserve MyBuff(buffersize)\nmybuff(buffersize) = chunk\nend sub\n</code></pre>\n\n<p>if chunk is an array of bytes, it would look more like:</p>\n\n<pre><code>buffersize=buffersize+ubound(chunk) 'or if it's a fixed-size chunk, just use that number\nredim preserve mybuff(buffersize)\nfor k%=0 to ubound(chunk) 'copy new information to buffersize\n  mybuff(k%+buffersize-ubound(chunk))=chunk(k%)\nnext\n</code></pre>\n\n<p>if you will be doing this frequently (say, many times per second) you'd want to do something like how the StringBuilder class works:</p>\n\n<pre><code>public BufSize&amp;,BufAlloc&amp; 'initialize bufalloc to 1 or a number &gt;= bufsize\npublic MyBuff() as byte\n\nsub getdata()\nbufsize=bufsize+ubound(chunk)\nif bufsize&gt;bufalloc then\n  bufalloc=bufalloc*2\n  redim preserve mybuff(bufalloc)\nend if\nfor k%=0 to ubound(chunk) 'copy new information to buffersize\n  mybuff(k%+bufsize-ubound(chunk))=chunk(k%)\nnext\nend sub\n</code></pre>\n\n<p>that basically doubles the memory allocated to mybuf each time the pointer passes the end of the buffer.  this means much less shuffling around of memory.</p>\n"}]
['https://Stackoverflow.com/questions/77382', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']