Sorting multiple dimensions of an array

  • Thread starter Thread starter lgbjr
  • Start date Start date
L

lgbjr

Hi All,

Is there a way to sort multiple dimensions of an array in VB.NET? Let's say
I have the following in a multi-dimension array:

3081 100 2
3081 100 1
3081 20 1
3081 1 2
3021 100 2
3021 100 1
3021 20 1
3021 1 2

I need to sort the first dimension, then the 2nd, then the 3rd, to get:

3021 1 2
3021 20 1
3021 100 1
3021 100 2
3081 1 2
3081 20 1
3081 100 1
3081 100 2

Initially, I put the values together in one string, like 3021-1-2 in a
single dimension array, then sorted that, but, because the value is a
string, the sort result is not what I'm looking for. Instead, I get:

3021-1-2
3021-100-1
3021-100-2
3021-20-1
etc.

I know I can create a dataset, table, columns, etc. and use a grid that
supports multi-column sorting, but I don't need the grid. I just need to
sort the array.

Eventually, this data is combined with other data and streamed out to a
file. I can live with the string sort as above, but I'd prefer to sort the
multi-dimension array so that the result is a correct numeric sort.

any ideas?

TIA

Lee
 
lgbjr said:
Hi All,

Is there a way to sort multiple dimensions of an array in VB.NET? Let's say
I have the following in a multi-dimension array:

3081 100 2
3081 100 1
3081 20 1
3081 1 2
3021 100 2
3021 100 1
3021 20 1
3021 1 2

I need to sort the first dimension, then the 2nd, then the 3rd, to get:

3021 1 2
3021 20 1
3021 100 1
3021 100 2
3081 1 2
3081 20 1
3081 100 1
3081 100 2

Seems 2 me that since the dimensions are apparently not related, it would be
easier to just use 3 separate arrays, then sort each separately.
 
Back
Top