Finding the maxiumum of a list of numbers in the List Box

06-03-2005, 05:36 PM
Ok, I need help finding out how to write the code for a label to show the minimum or maxiumum of the numbers in the list box. The list box has a list of temperatures in it; and the label needs to have the maxiumum temperature (corresponding label have the miniumum temperature). The number is a single, with 4 decimal places.



06-03-2005, 05:45 PM
Here is an example on how to find the lowest number,

Dim lowest As Single
Dim x As Integer
lowest = List1.List(0)
For x = 1 To List1.ListCount - 1
If List1.List(x) < lowest Then lowest = List1.List(x)
Next x
MsgBox "The Lowest Number = " & lowest

it cycles through each item in the list, and compares it to the lowest (or what it thinks is the lowest), if it finds an item that is lower, then it replaces the old value for the lowest with the new value.
this can be easily modified to find the highest.

Cerian Knight
06-03-2005, 07:00 PM
While the list entries are being added is a good time to track MinTemp and MaxTemp. Set MaxTemp to a tiny number and MinTemp to a very large number when the program starts. Then as each temp is added check and see if it is greater than Min or less than Max and store them as the new Min or Max. After the list is created, use the Format command to set the label captions.

06-03-2005, 07:12 PM
Thanks for your help.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum