Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 [RESOLVED] Sorting a multidimensional array

$
0
0
I am hoping someone can point me in the right direction. I am trying to sort cities by population. The cities are stored in a multidimensional array from a file:

Example (using only 3 of the thousands of cities that are stored in the array):

Code:

Dim Cities(2, 2) as string

Cities(0, 0) = "Phoenix" '//City Name
Cities(0, 1) = "Arizona" '//City's State
Cities(0, 2) = "1469471" '//City's Population

Cities(1, 0) = "New York" '//City Name
Cities(1, 1) = "New York" '//City's State
Cities(1, 2) = "8244910" '//City's Population

Cities(2, 0) = "Los Angeles" '//City Name
Cities(2, 1) = "California" '//City's State
Cities(2, 2) = "3819702" '//City's Population


When sorted, I would like for them to be changed into this sequence (highest to lowest):


Code:

Cities(0, 0) = "New York" '//City Name
Cities(0, 1) = "New York" '//City's State
Cities(0, 2) = "8244910" '//City's Population

Cities(1, 0) = "Los Angeles" '//City Name
Cities(1, 1) = "California" '//City's State
Cities(1, 2) = "3819702" '//City's Population

Cities(2, 0) = "Phoenix" '//City Name
Cities(2, 1) = "Arizona" '//City's State
Cities(2, 2) = "1469471" '//City's Population

Would like to be able to call a function, sub or routine to sort the cities based on (x, 2) contents of the array (eg. population). I was hoping there might be a simple, straightforward way for doing this.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>