Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

multi array sort

Status
Not open for further replies.

enque

Civil/Environmental
Dec 7, 2002
20
I have this:
v(0, 0) = 4
v(0, 1) = 100
v(1, 0) = 5
v(1, 1) = 800
v(2, 0) = 2
v(2, 1) = 200
v(3, 0) = 6
v(3, 1) = 50
v(4, 0) = 1
v(4, 1) = 550

And I want this:
v(0,0)= 1
v(0,1)=550
v(1,0)= 2
v(1,1)=200
v(2,0)= 4
v(2,1)=100
v(3,0) = 5
v(3,1)=800
v(4,0) = 6
v(4,1)=50

How can I code it?
 
Replies continue below

Recommended for you

Dear Enque,

Your problem is to sort a group of records, on the value of a particular column.

I do not know what your program exactly does, but I think it collects multiple sets of related data, and analyzes them. In order to solve this type of problems systematically, you need to understand any (or both) of the two following concepts.

1. User-defined data-structures
2. Database

These topics are a bit elaborate, so cannot be explained here. But, these are explained in any intermediate-level VB book.

I could send an example code for solving this, but for some reason I consider that pointless, without explaining the concept.

Regards

Yeasir Rahul

Principal, VoltSmith Technologies
 
Personally I would use VB to create an Access database with your table in it and then use the Jet functionality to do the sorting. It may not sound efficient but computers are fast and the functionality for sorting that a database gives is worth it. And using a db you get and filtering and storing between sessions and much more.
 
Hi, You could use a collection object, where the number 1,2,3,etc is converted into a string and used as the key, the larger number is used as the value.

e.g.

Dim ccol As Collection
Set ccol = New Collection
' note that the order that the data is entered is unimportant
ccol.Add Key:=Str(2), Item:=200
ccol.Add Key:=Str(1), Item:=550
' ...

Debug.Print ccol(Str(1))
Debug.Print ccol(Str(2))
' ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor