+ Reply to Thread
Results 1 to 3 of 3

Need help with a easy programming question

  1. #1
    Registered User
    Join Date
    04-10-2006
    Posts
    2

    Need help with a easy programming question

    So I have to seperate arrays. I have a program written that will find the maximum value from one of the arrays. I need to have the program output a value from the second array that corresponds to the location of the max value from the first array. What should I use to correspond the two arrays in the end?

  2. #2
    Registered User
    Join Date
    04-10-2006
    Posts
    2
    My maximum value looks like this.

    Option Explicit
    Option Base 1
    Function MaxVal(DataArray)
    Dim NumRows As Integer, NumCols As Integer
    Dim i As Integer, j As Integer
    MaxVal = DataArray(1, 1)
    NumRows = DataArray.Rows.Count
    NumCols = DataArray.Columns.Count
    For i = 1 To NumRows
    For j = 1 To NumCols
    If DataArray(i, j) > MaxVal Then
    MaxVal = DataArray(i, j)
    End If
    Next j
    Next i
    End Function

  3. #3
    Jim Cone
    Guest

    Re: Need help with a easy programming question


    My interpretation...
    Jim Cone
    San Francisco, USA
    http://www.realezsites.com/bus/primitivesoftware

    Function MaxVal(ByRef DataArray() As Double, _
    ByRef TheOtherArray() As Double) As Double
    Dim NumRows As Long
    Dim NumCols As Long
    Dim i As Long
    Dim j As Long
    Dim x As Long
    Dim y As Long

    MaxVal = DataArray(1, 1)
    NumRows = UBound(DataArray)
    NumCols = UBound(DataArray, 2)
    For i = 1 To NumRows
    For j = 1 To NumCols
    If DataArray(i, j) > MaxVal Then
    x = i
    y = j
    End If
    Next j
    Next i
    MaxVal = TheOtherArray(x, y)
    End Function
    '----
    Sub NewsgroupTestForMaxVal()
    'Create two arrays and call the MaxVal function.
    Dim arrFirst() As Double
    Dim arrSecond() As Double
    Dim lngN As Long
    Dim x As Double

    ReDim arrFirst(1 To 4, 1 To 5)
    ReDim arrSecond(1 To 4, 1 To 5)

    'Load the arrays
    For lngN = 1 To 4
    For x = 1 To 5
    arrFirst(lngN, x) = lngN + x * 2
    arrSecond(lngN, x) = lngN + x * 3
    Next
    Next
    'For reference purposes, to check the result returned.
    'Range("A1:E4").Value = arrFirst()
    'Range("G1:K4").Value = arrSecond()

    'Call the function
    x = MaxVal(arrFirst, arrSecond)
    MsgBox x
    End Sub
    '-------------



    "NickCo7" wrote in message
    My maximum value looks like this.

    Option Explicit
    Option Base 1
    Function MaxVal(DataArray)
    Dim NumRows As Integer, NumCols As Integer
    Dim i As Integer, j As Integer
    MaxVal = DataArray(1, 1)
    NumRows = DataArray.Rows.Count
    NumCols = DataArray.Columns.Count
    For i = 1 To NumRows
    For j = 1 To NumCols
    If DataArray(i, j) > MaxVal Then
    MaxVal = DataArray(i, j)
    End If
    Next j
    Next i
    End Function


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1