0

hi

i want code in VB.net 2008 or 2005 to find Max for negative value ??? also this function can find max for positive value

Example:
-223.5 , -456.7 , - 999.7 , -78.9

Max= -78.9

please help me :(

2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by zahraj
0

OK, you didn't say how you got those values, so I just added them to an arraylist during form_load event. My code is a little backwards, but it works for me, lol.

Dim dblArray As New ArrayList()
        dblArray.Add("-223.5")
        dblArray.Add("-78.9")
        dblArray.Add("-999.7")
        dblArray.Add("-456.7")

        Dim holdMin As String = ""
        Dim holdMax As String = ""


        'get max & min
        For i = 0 To dblArray.Count - 1
            For i2 = 1 To dblArray.Count - 1
                If dblArray.Item(i) > dblArray.Item(i2) Then
                    If dblArray.Item(i) > holdMax Then
                        holdMax = dblArray.Item(i)
                        holdMin = dblArray.Item(i2)
                    Else
                        holdMax = dblArray.Item(i2)
                        holdMin = holdMin
                    End If
                ElseIf dblArray.Item(i) < dblArray.Item(i2) Then
                    If dblArray.Item(i) < holdMin Then
                        holdMin = dblArray.Item(i)
                        holdMax = dblArray.Item(i2)
                    Else
                        holdMin = dblArray.Item(i2)
                        holdMax = holdMax
                    End If
                End If
            Next
        Next

'this is the minimum value for some reason :P
        TextBox2.Text = holdMax
'this is the maximum value for some reason :P
        TextBox3.Text = holdMin

The max and min values are backwards for me, but it works, sometimes, lol. See if that helps any. It's not perfect but should help you out some.

0

hi crazyhorse09

thanks you help me in my project

thanks so much.....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.