Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2006

Tip: Looking for answers? Try searching our database.

Address position in array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yankee1423 - 29 Dec 2006 16:34 GMT
Say I have a 5 by 5 array.  I would like to find the highest value in
each column of that array and also its position.  For example in the
following example I'd like to get return the following data:

0, 2, 3, 4, 1
2, 3, 9, 10, 3
3, 4, 6, 7, 8
3, 6, 4, 2, 1
6, 8, 0, 3, 4

6 (5,1)
8 (5,2)
9 (2,3)
10 (2,4)
8 (3,5)

I am able to find the 6, 8, 9, 10, 8 number with a sort function but
can't seem to get the position.  Here is the sort function I'm using:
--------------------------------------------------------
Sub Sort(Arr() As Double, first As Integer, last As Integer)
Dim I As Integer
Dim J As Integer
Dim SwapStr As Double
Dim Cont As Double
Dim K As Integer

For K = 1 To 5
For I = first To last - 1
   For J = I + 1 To last
       If Arr(I, K) > Arr(J, K) Then
       SwapStr = Arr(I, K)

       Arr(I, K) = Arr(J, K)
       Arr(J, K) = SwapStr
       End If
   Next J
   Next I

Next K
Marco Pagliero - 29 Dec 2006 23:35 GMT
Yankee1423 schrieb:

> Say I have a 5 by 5 array.  I would like to find the highest value in
> each column of that array and also its position.  For example in the
[quoted text clipped - 14 lines]
> I am able to find the 6, 8, 9, 10, 8 number with a sort function but
> can't seem to get the position.  Here is the sort function I'm using:

I don't understand why you'd need to sort the array at all. If I need
to know for every column the highest value and its position I do it
like this:

Dim Result(MaxCol, 1)
For Col = 1 To MaxCol
     For Row = first To last
           If Arr(Col, Row) > Result(Col, 0) Then
              Result(Col, 0) = Arr(Col, Row)
              Result(Col, 1) = Row
              end if
    Next Row
Next Col

At end I have in
Result(1,0) the highest value in the 1st column and in Result(1,1) its
position,
Result(2,0) the highest value in the 2nd column and in Result(2,1) its
position,
Result(3,0) the highest value in the 3rd column and in Result(3,1) its
position,
...

Greetings
Marco P
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.