Accessing one dimension of a multidimensional array

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have a multidimensional array declared as the following:


Dim guesses(14, 5) As Integer


I want to assign all values in a specific dimension to another array
declared as follows:


Dim currguess(5) As Integer


I would have thought this would be done using something like the following
where x is the dimension I want to copy:


currguess=guesses(x)


However, VB.NET does not seem to like this. What can I do to copy only a
specific dimension to another array? Thanks.
 
youd need to put it in a for loop and do it manually

Dim guesses(14, 5) as integer
Dim currGuess(5) as integer

for x as Integer = 0 to 5

currGuesses(x) = guesses(3,X)

Next
 
hello,

do you realize, if you're copying the last dimension, that is
practically all the values in the entire array (think of it as a
relational database where the second dimension is sub/child table
related to the parent table which would be the first dimension), if
you're refering to an array of arrays, that is different ie:

dim arrayOfArrays()() as integer

Here the where the last dimension is all integers, and the first
dimension is of type "Array" ie: ( "TypeOf arrayOfArrays(0) Is Array"
would be true and "TypeOf arrayOfArrays(0)(0) Is Integer" would also be
true, of course given arrayOfArrays are initialized).

of course, if you are just trying to copy the first dimension, or any
dimension except the last one, then that would make sense. looping it
would do, however, for efficiency purposes you should always try to use
microsofts implementations which apply to objects of type Array.

I believe they have various methods, but to make use of these you would
need to create an array of arrays, and just access the objects
following your array like this...

arrayOfArrays(3). [and this is where the intellisense will help you
with more information, since this is an Array object, you'll get all
the mass data manipulation methods available]

hope that helps, let me know if you would like further clarification.

cheers.
 
Back
Top