473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sorting a two-dimensional array

How do you sort a 2D array?

Dim myArray(10000, 9) As String

myArray contains 10000 records with 9 fields. I want to sort on the
Ninth field.
I want to be able to use the sort method, but how?

myArray.sort( ?, ?)
Thanks,
Moondog

Aug 7 '07 #1
2 7117
Moondog,

I wished to that there was a simple sort method, however it does not exist
in dotNet.

You have to create everytime new a sort method by using IComparable.
http://msdn2.microsoft.com/en-us/lib...omparable.aspx

If you say that it is an ommission, than we agree.

Cor
"moondog" <di****@verizon.netschreef in bericht
news:11**********************@q3g2000prf.googlegro ups.com...
How do you sort a 2D array?

Dim myArray(10000, 9) As String

myArray contains 10000 records with 9 fields. I want to sort on the
Ninth field.
I want to be able to use the sort method, but how?

myArray.sort( ?, ?)
Thanks,
Moondog
Aug 7 '07 #2
Hi Moondog,

The Sort method only works on single dimension arrays. Rather than using a
two dimensional array, you could use a jagged array, e.g:

Dim myArray(1000)() As String

' populate the array, ensuring there are 0 to 9 items in each slot
' the sort
Array.Sort(s, New Comparison(Of String())(AddressOf JaggedArrayComparer))

Private Function JaggedArrayComparer(ByVal item1 As String(), ByVal item2
As String()) As Int32
Return item1(9).CompareTo(item2(9))
End Function
Regards,

Bill.

"moondog" <di****@verizon.netwrote in message
news:11**********************@q3g2000prf.googlegro ups.com...
How do you sort a 2D array?

Dim myArray(10000, 9) As String

myArray contains 10000 records with 9 fields. I want to sort on the
Ninth field.
I want to be able to use the sort method, but how?

myArray.sort( ?, ?)
Thanks,
Moondog
Aug 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Pratt | last post by:
I have been using the following for sorting a list of dictionaries. This works but only provides sorting on a single key. I am wanting to extend this with a better comparison expression so that it...
9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
12
by: CJM | last post by:
How can I dynamically sort the results from a Stored Procedure? Or more importantly, what is the fastest and most efficient way? I know I can do the sorting within the recordset in ASP, but AFAIK...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
0
by: gopi2ks | last post by:
HI I USE THIS below code for sorting but, when we are click sorting columns , then it will showing the next page rows in sorting also, i need only this page rows only sorting waiting for ur reply...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
4
by: rajtalent | last post by:
hi all, I want to sort the colum when clicks the columnheader using vb.net 2005 .But i receive the following error "Error 1 Overload resolution failed because no accessible 'New' accepts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.