Dynamic Arrays in VB

Started by
5 comments, last by intrest86 22 years, 4 months ago
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!
Turring Machines are better than C++ any day ^_~
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.
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.
Dim ListSpeed() as interger
ReDim ListSpeed(100)
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.
Trying is the first step towards failure.
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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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.
Trying is the first step towards failure.
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)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

This topic is closed to new replies.

Advertisement