Archived

This topic is now archived and is closed to further replies.

intrest86

Dynamic Arrays in VB

Recommended Posts

intrest86    742
I have never been able to make a dynamic array in VB..., how is it done? If one person would write a book on DirectX in VB, I would make them a rich man!

Share this post


Link to post
Share on other sites
jenova    122
i haven''t used VB in a while, but i remember. "dim()".

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
ragonastick    134
To add to what Magmai said, you can also use:

Redim Preserve ListSpeed(200)

This means that the original contents of the array will be saved. Only use this if you need to though, as it can be slower.

Oh, and the MSDN is an even better source of info for little language problems like this... use it

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
Promit    13246
When ReDim(Arr(X)) is used, it will delete all the contents in the array and reinit them to 0. THis can be an extremely fast way to reset a dynamic array; use it!

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites
ragonastick    134
Also for fixed arrays, you can use that trick:

Sub ClearArray(MyArray() As Long)
Redim MyArray(UBound(MyArray))
End Sub

But it is better to just use Erase:

Erase MyArray

if this is done on a dynamic array, then you need to redimension because they are lost as well, so

Erase MyDynamicArray
Redim MyDynamicArray(Size)

But since Redim will clear the contents anyway, we get rid of the erase.

Oh, and it is good practice to Erase dynamic arrays when you are finished with them.

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
krez    443
quote:
Original post by ragonastick
Also for fixed arrays, you can use that trick:

Sub ClearArray(MyArray() As Long)
Redim MyArray(UBound(MyArray))
End Sub


you cannot redim a fixed array.
try it.

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites