Help - Highest & lowest Val from 5 textboxes

tobywuk

New member
Joined
Apr 26, 2007
Messages
1
Programming Experience
Beginner
Hello,

I am a student and have not been doing VB.NET long.

I have 5 testboxes where the user enteres values. I need to select the highest and lowest value from these boxes and put the two figures in there own veriable.

Please not i am a beginer, so i only need very simple code. Also i need the result to be calculates with a loop.

Here is the code i have:

VB.NET:
 'Set Global Veraibales
        Dim MaxValue As Integer
        Dim MinValue As Integer
        Dim count As Integer
        Dim marks(4) As Integer
        'Find Min Value
        Dim marksC As Integer = 99999
        marks(0) = txtMark1.Text
        marks(1) = txtMark2.Text
        marks(2) = txtMark3.Text
        marks(3) = txtMark4.Text
        marks(4) = txtMark5.Text
        For count = 0 To 4
            If marks(count) < marksC Then
                MinValue = marks(count)
            End If
            'put value in minValue
            marksC = MinValue
        Next
        lblResult.Text = MinValue
        'Find MaxValue
        Dim marksC1 As Integer = -99999
        marks(0) = txtMark1.Text
        marks(1) = txtMark2.Text
        marks(2) = txtMark3.Text
        marks(3) = txtMark4.Text
        marks(4) = txtMark5.Text
        For count = 0 To 4
            If marks(count) > marksC1 Then
                MaxValue = marks(count)
            End If
        Next
        lblResult2.Text = MaxValue

Please can you help :)
 
Finding highest and lowest values in an array

Before starting the For loop, assign an arbitrary value to high and to low. For example:
high = marks(0)
low = marks(0)
Then inside the loop, compare each of the array values (from 1 to 4) with high and low. if the current value is higher than high, then reassign it to high. Ditto for low.
 
why not just sort the array then pull the lowest value from the 0 and the highest being the upperbound of the array?
 
Back
Top