Hi! I am having trouble with one little part of my program
I have to find the min in a collection of data that's already been placed in a text file in the bin folder.
I know that if I were finding the largest, I could set Dim largest = 0, but this does not work for min. We cannot use negative numbers so the smallest would end up always being zero.
I need to know how to get around that.
where I have smallest = 999, I need it to be able to not just check up to 999 but to infinity if necessary because the smallest will always be zero if I set it equal to zero.
Thanks.
I have to find the min in a collection of data that's already been placed in a text file in the bin folder.
I know that if I were finding the largest, I could set Dim largest = 0, but this does not work for min. We cannot use negative numbers so the smallest would end up always being zero.
I need to know how to get around that.
Code:
Private Sub btnFindSmallest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindSmallest.Click
'Finds smallest of a collection of numbers.
Dim smallest, num As Double
smallest = 999
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
num = CDbl(sr.ReadLine)
If num < smallest Then
smallest = num
End If
Loop
End Sub
where I have smallest = 999, I need it to be able to not just check up to 999 but to infinity if necessary because the smallest will always be zero if I set it equal to zero.
Thanks.