Directly and dynamically assigning values to an array

astevens

Member
Joined
Jun 30, 2010
Messages
5
Programming Experience
1-3
I am trying to figure out how to assign a 1-dimensional array value I get from a function directly into an element in a 2-dimensional array. An example would be

VB.NET:
Dim Results(7)() as Double
Results(0) = myFunction() ' returns an array with 5 doubles

What is the correct syntax for this, if any? I'm still having a bit of difficulty switching over from Python arrays, which work a lot better, it seems.

Thanks!

Aaron
 
What you have there is a jagged array (array of arrays) and the code is valid. A multidimensional array is a matrix of single cells, and you can't copy an array over a dimension by assigning it to a single cell, you'd have to iterate the indexes/values. Arrays in Visual Basic
 
I was afraid I was going to have to iterate over it. I thought for sure there would be a way of directly assigning the variable, but I guess I'm just too used to Python =P

VB.NET:
myArray = [[]]*7
myArray[0] = myFunc()
 
you can, if it's a jagged array... your example code IS a jagged array, so it's possible.

VB.NET:
''this is an array of arrays
Dim jaggedArray()() As Integer
''you can replace any array in the array of arrays.


''this is a complex matrix... complex because you can have many dimensions
Dim multiDimensionalArray(,) As Integer
''this is not an array of arrays, so you can't replace an array in it... there is no array in it. 
''It's a large block of integers instead. You'd have to loop and add each integer one at a time.
 
echo echo...
 
Thanks, I'll have to keep that in mind for future projects. This one actually became easier to deal with each array individually instead of gathering them up and dealing with them all at once.
 
Back
Top