2

I have a function that returns a 1D-array like this:

Public Function KeyConvert([args]) As Byte()

and a 2 dimension array:

Public KeyList(15, 5) As Byte

Which can be seen as 15 rows,each row is a 5 element array, as we all already knew.

Now I want to call the function and assign the result (which is a 1D array) to a row (say row 4) in the KeyList array. At first I thought the code should be like

Keylist(4) = KeyConvert([args])

But that didn't work. I cannot find a way to reference to that specific row.

So anybody have any idea? Thank you very much

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
king0deu
  • 21
  • 1
  • 2

2 Answers2

2

You want a jagged array, not a m-d one.

Something closer to:

Public KeyList(15)() As Byte
Marc
  • 9,254
  • 2
  • 29
  • 31
  • Thank you everyone. I think I got confused between the two definitions: 2 dimensional array and an array of arrays. This should solve my problem – king0deu Jul 08 '11 at 03:30
0

There is no notion in VB.Net (or C#) of "a row" (or "a column") in a 2-dimensional array. Array elements in .Net can only be accessed one at a time.

If you make your KeyList variable be a one-dimensional array of 5-element arrays, then you will be able to use the syntax you showed.

If you need to keep KeyList as a 2-dimensional array so that you can more easily access any single "point" within it, then you can write a method that is passed the row to update and the 5-element array whose elements are to be copied, and have that method copy the 5 values one at a time into the respective columns.

J.Merrill
  • 1,233
  • 14
  • 27