If the array is small, and new data is infrequently added, an easy way would be to:
public BufferSize as long 'or you can just use Ubound(mybuff), I prefer a tracker var tho
public MyBuff
private sub GetChunk()
dim chunk as byte
'get stuff
BufferSize=BufferSize+1
redim preserve MyBuff(buffersize)
mybuff(buffersize) = chunk
end sub
if chunk is an array of bytes, it would look more like:
buffersize=buffersize+ubound(chunk) 'or if it's a fixed-size chunk, just use that number
redim preserve mybuff(buffersize)
for k%=0 to ubound(chunk) 'copy new information to buffersize
mybuff(k%+buffersize-ubound(chunk))=chunk(k%)
next
if you will be doing this frequently (say, many times per second) you'd want to do something like how the StringBuilder class works:
public BufSize&,BufAlloc& 'initialize bufalloc to 1 or a number >= bufsize
public MyBuff() as byte
sub getdata()
bufsize=bufsize+ubound(chunk)
if bufsize>bufalloc then
bufalloc=bufalloc*2
redim preserve mybuff(bufalloc)
end if
for k%=0 to ubound(chunk) 'copy new information to buffersize
mybuff(k%+bufsize-ubound(chunk))=chunk(k%)
next
end sub
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.