Results 1 to 4 of 4

Thread: [Resolved] Determine the member of a type with the highest value

  1. #1

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Resolved [Resolved] Determine the member of a type with the highest value

    having a hard time determining which member of a private type has the highest value.

    Bubble Sorting doest appear loggical, or if it does I just can't see it from this view...


    VB Code:
    1. Private Type ThisIsATest
    2.  lThisisALong as long
    3.  sThisIsAName as string
    4. End Type
    5. Dim Test(39) as ThisIsATest
    6.  
    7.  
    8. Private Sub Form_Load()
    9.  
    10. Test(0).lThisisALong = 4123
    11. Test(1).lThisisaLong = 31
    12. Test(2).lThisisaLong = 312355
    13. End Sub

    any ideas how to determine which is the highest?
    Last edited by Hack; Feb 2nd, 2006 at 01:18 PM. Reason: Added green "resolved" checkmark
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Determine the member of a type with the highest value

    Loop through the entire array and check that the value in the current Index is higher than the previous value.

    VB Code:
    1. Dim lngIdx As Long
    2.     Dim lngValue As Long
    3.     Dim lngMaxIdx As Long
    4.  
    5.     lngValue = -2000000000
    6.  
    7.     For lngIdx = 0 To UBound(Test)
    8.  
    9.         If Test(lngIdx).lThisisALong > lngValue Then
    10.             lngValue = Test(lngIdx).lThisisALong
    11.             lngMaxIdx = lngIdx
    12.         End If
    13.  
    14.     Next
    15.  
    16.     Debug.Print "The array element " & lngMaxIdx & " contains the highest value of " & lngValue

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Determine the member of a type with the highest value

    I did something similar, with a function..
    Code:
    Private Sub Command1_Click()
        MsgBox getmaxValue
    End Sub
    
    Private Function getmaxValue() As Long
    Dim i       As Long
    Dim TempVal As Long
    
        TempVal = -999999999
        For i = 0 To UBound(Test)
            If Test(i).lThisisALong > TempVal Then TempVal = Test(i).lThisisALong
        Next
        getmaxValue = TempVal
    End Function

  4. #4

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: Determine the member of a type with the highest value

    Thanks guys, works like a charm
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

Posting Permissions

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



Click Here to Expand Forum to Full Width