Dynamic Arrays in VB
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!
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.
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.
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.
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.
-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.
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.
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.
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement