Hello, I have two problems I’m having trouble solving. The first involves a program that opens a text file with a bunch of random numbers out of order listed line by line. I have to list the Highest and the second Highest in a list box using loops and if statements. I had no trouble figuring out how to get the highest but how do I go about generating the second highest. The code is listed below.
The second problem I am having is similar to the first but I have another text file that consists of a bunch names that are listed in Alphabetical order. Some of the names are repeated more than once. I have to use loops and if statements to display the file of names but for those that are repeated in the text file only list once. I have no clue how to go about doing this one. Any help would be great.
Thanks.
Code:
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim SR As IO.StreamReader = IO.File.OpenText("BID.TXT")
Dim Bids As Double
Dim Highest As Double = 0
Dim SecondHighest As Double
Do While (SR.Peek <> -1)
Bids = CDbl(SR.ReadLine)
If Bids > Highest Then
Highest = Bids
End If
Loop
SR.Close()
lstdisplay.Items.Add("The Highest Bid is: " & FormatCurrency(Highest))
End Sub
Thanks.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SR As IO.StreamReader = IO.File.OpenText("NAMES.TXT")
Dim Name As String
Do While (SR.Peek <> -1)
Name = SR.ReadLine
Loop
End Sub
Comment