Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with sorting an array by a specific field 2

Status
Not open for further replies.

BFarley

Programmer
May 22, 2008
43
US
I have a text file that I have to work with frequently. It's submitted by a client, and I bring it into a VB.NET application to do various things.

Sample data:

Code:
DATE          EMP       JOBNO        AMT
7/25/2008     12345     XYZ12345     5.99
7/22/2008     23456     XYZ12346     4.99
7/21/2008     34567     XYZ12347     3.99

The file contains various job numbers. On occasion, I'll have to remove lines containing one or more job number. (Each job number may appear in multiple lines.) This can be time-consuming, as the file is seldom in order by job number.

What I'd like to do is put the lines in an array, and sort by JOBNO. When I load to an array and do an Array.Sort, it comes back in order by DATE (the first field).

I have all the code in place to read from and write to text files as needed. This one piece would make my life much easier. If an array is not the answer, I'm open to suggestions.

I'd thought of loading into a dataset and sorting there, but it seemed like a bit of a long way around; besides, I need to learn more about arrays and their usage.

Thanks in advance.

Bryant Farley

"The Dude Abides
 
.NET doesn't have any built-in functionality for sorting multidimensional arrays because it assumes that you will use datatables/datasets in place of arrays. That said, I think you should look into using a datatable to do this, not an array.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
jebenson is correct...there is no built-in functionality in .NET to sort multidimensional arrays. However, there appears to be a workaround. I've never attempted this, but this article ( provides some detail on how to do this (scroll down towards the bottom of the page). There is a link to download the source code to use in sorting multidimensional arrays.

Good Luck!
 
Thanks for the input, guys -- got it to work perfectly using a datatable & dataview. I wanted to make sure I wasn't overlooking any available technology & shorter way around it.

Bryant Farley

"The Dude Abides
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top