array setup

joe_pool_is

Well-known member
Joined
Jan 18, 2004
Messages
451
Location
Texas
I have tried to innitialize an array all in one step, like this:

intArray() = {1, 2, 3, 4, 5}
or
intArray = {1, 2, 3, 4, 5}

or many other methods similar. Nothing seems to work. The only way I have managed to populate the elements of the array is:

intArray(0) = 1
intArray(1) = 2
intArray(2) = 3
intArray(3) = 4
intArray(4) = 5

Is there a more elegant method?
 
Does this only work when the array is innitialized? Ive tried:
Code:
                dataout = {0, 1, 2, 3, 4, 5, 6}
                dataout() = {0, 1, 2, 3, 4, 5, 6}
The first one gives me "Expression expected." at the first curley brace. The second attempt gives me "Number of indices is less than the number of dimensions of the indexed array." and "Expression expected." like before.
 
afaik you can only assign an array like that when its declared.

look into Array copying.

[VB]
Class X
Protected Shared arr As Integer = {0,0,1,2,1,23,5}

Public Sub New()
Dim y As Integer()

y = DirectCast(arr.Clone(), Integer())
or
ReDim y(arr.Length() - 1)
arr.CopyTo(y, 0)

End Sub


End Class
[/VB]
 
Back
Top