|
-
Feb 2nd, 2006, 12:40 PM
#1
Thread Starter
Fanatic Member
[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:
Private Type ThisIsATest
lThisisALong as long
sThisIsAName as string
End Type
Dim Test(39) as ThisIsATest
Private Sub Form_Load()
Test(0).lThisisALong = 4123
Test(1).lThisisaLong = 31
Test(2).lThisisaLong = 312355
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
-
Feb 2nd, 2006, 12:47 PM
#2
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:
Dim lngIdx As Long
Dim lngValue As Long
Dim lngMaxIdx As Long
lngValue = -2000000000
For lngIdx = 0 To UBound(Test)
If Test(lngIdx).lThisisALong > lngValue Then
lngValue = Test(lngIdx).lThisisALong
lngMaxIdx = lngIdx
End If
Next
Debug.Print "The array element " & lngMaxIdx & " contains the highest value of " & lngValue
-
Feb 2nd, 2006, 12:55 PM
#3
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
-
Feb 2nd, 2006, 01:04 PM
#4
Thread Starter
Fanatic Member
Re: Determine the member of a type with the highest value
Thanks guys, works like a charm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|