How to find Max????

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2009
Posts: 7
Reputation: zahraj is an unknown quantity at this point 
Solved Threads: 0
zahraj zahraj is offline Offline
Newbie Poster

How to find Max????

 
0
  #1
Mar 18th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 44
Reputation: crazyhorse09 is an unknown quantity at this point 
Solved Threads: 4
crazyhorse09 crazyhorse09 is offline Offline
Light Poster

Re: How to find Max????

 
0
  #2
Mar 18th, 2009
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.

  1. Dim dblArray As New ArrayList()
  2. dblArray.Add("-223.5")
  3. dblArray.Add("-78.9")
  4. dblArray.Add("-999.7")
  5. dblArray.Add("-456.7")
  6.  
  7. Dim holdMin As String = ""
  8. Dim holdMax As String = ""
  9.  
  10.  
  11. 'get max & min
  12. For i = 0 To dblArray.Count - 1
  13. For i2 = 1 To dblArray.Count - 1
  14. If dblArray.Item(i) > dblArray.Item(i2) Then
  15. If dblArray.Item(i) > holdMax Then
  16. holdMax = dblArray.Item(i)
  17. holdMin = dblArray.Item(i2)
  18. Else
  19. holdMax = dblArray.Item(i2)
  20. holdMin = holdMin
  21. End If
  22. ElseIf dblArray.Item(i) < dblArray.Item(i2) Then
  23. If dblArray.Item(i) < holdMin Then
  24. holdMin = dblArray.Item(i)
  25. holdMax = dblArray.Item(i2)
  26. Else
  27. holdMin = dblArray.Item(i2)
  28. holdMax = holdMax
  29. End If
  30. End If
  31. Next
  32. Next
  33.  
  34. 'this is the minimum value for some reason :P
  35. TextBox2.Text = holdMax
  36. 'this is the maximum value for some reason :P
  37. 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.
Last edited by crazyhorse09; Mar 18th, 2009 at 6:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 7
Reputation: zahraj is an unknown quantity at this point 
Solved Threads: 0
zahraj zahraj is offline Offline
Newbie Poster

Re: How to find Max????

 
0
  #3
Mar 19th, 2009
hi crazyhorse09

thanks you help me in my project

thanks so much.....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC