Jump to content
  • Advertisement

Archived

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

intrest86

Dynamic Arrays in VB

This topic is 6026 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!