# Max and Min Numbers in Array • ### Question

• Hi All,

I just to know how to find Maxima and minima in List R then show the digit count .

Example at line 2 from text file the result show as bellow; Result line 2 is Max =12(2) at digits = 7,5

```Option Strict On
Option Explicit On
Option Infer Off

Imports System.IO
Imports System.Data

Public Class Form1

Private R As New List(Of Integer)

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
TextBox1.Clear()

'tox text file= "6005,1426,1385,5732,2229,3699,9950,8881,6223,0893,7574,3507,7538,4630,6523,2446,2223,5198,1997,4966,3500,0590,7527"
'               "8992,4563,6716,8222,5077,7888,5657,1359,7325,1379,5359,9863,4108,4404,2832,5788,6083,2505,5301,9701,6266,7672,1792"
'               "1344,7917,2893,4315,1381,6425,4200,3574,7456,1910,9244,6718,9413,1915,1590,5906,2135,2878,1951,0434,7359,1369,3184"

Do While sr.Peek <> -1

Dim StringToCheck As String = sr.ReadLine()

For i As Integer = 0 To 9
Dim StringToFind As String = CStr(i)
Dim Result As String = StringToCheck.Count(Function(c As Char) c = StringToFind).ToString

TextBox1.AppendText(CStr(i) & "  =>   " & Result & " " & vbCrLf)
Next

Dim min As Integer = Integer.MaxValue, max As Integer = Integer.MinValue, Value As Integer = 0

For i As Integer = 1 To R.Count - 1
Value = R(i)

If Value < min Then
min = Value
End If

If Value > max Then
max = Value
End If
Next

TextBox1.AppendText("Max Numbers =" & max & "     " & "Min Numbers =" & min & vbCrLf)

Loop

End Sub

End Class
```

Saturday, July 29, 2017 5:59 AM

• Example at line 2 from text file the result show as bellow;

You need to reset R each time the loop goes around.  Currently your min-max calculation is finding the min and max for all rows processed so far. You want the result for the current line only.

Why are you excluding the first item from your calculation?

• Marked as answer by Saturday, July 29, 2017 7:07 AM
Saturday, July 29, 2017 6:41 AM

### All replies

• Example at line 2 from text file the result show as bellow;

You need to reset R each time the loop goes around.  Currently your min-max calculation is finding the min and max for all rows processed so far. You want the result for the current line only.

Why are you excluding the first item from your calculation?

• Marked as answer by Saturday, July 29, 2017 7:07 AM
Saturday, July 29, 2017 6:41 AM
• yes,need to reset that Loop...then all lines calculation correct answer .Line 2 now correct max number = 12.

```            Dim min As Integer = Integer.MaxValue, max As Integer = Integer.MinValue, Value As Integer = 0

For i As Integer = 1 To R.Count - 1

Value = R(i)

If Value < min Then
min = Value
End If

If Value > max Then
max = Value
End If
Next

TextBox1.AppendText("Max Numbers =" & max & "     " & "Min Numbers =" & min & vbCrLf)

R.Clear()

Loop```

Acamar,

How to show that max number at line 1 is 12 and the digit is 2'

At line 2 show max number is 12 and the digit is 5,7

At line 3 show max number is 17 and the digit is 1.

Saturday, July 29, 2017 7:06 AM
• How to show that max number at line 1 is 12 and the digit is 2'