Just finishing up this assignment..

I need a code for the "Highest and Lowest" cmd button that will display the name and score in text boxes for the golfers with the highest and lowest from the golfer.txt file.

Here is my GUI & code so far.....

[IMG]http://www.geocities.com/rc_og/vb1.jpg[/IMG]

Private Sub cmdDisplay_Click()
Dim strName As String, intScore As Integer
Open "C:\Documents and Settings\Administrator\Desktop\golfer.txt" For Input As #6
Do Until EOF(6)
Input #6, strName, intScore
If intScore <= 70 Then
lstGolfer.AddItem strName & " " & intScore & "Professional"
ElseIf intScore <= 79 Then
lstGolfer.AddItem strName & " " & intScore & "Club Champ"
ElseIf intScore <= 89 Then
lstGolfer.AddItem strName & " " & intScore & "Good"
ElseIf intScore <= 99 Then
lstGolfer.AddItem strName & " " & intScore & "Fair"
ElseIf intScore > 99 Then
lstGolfer.AddItem strName & " " & intScore & "Duffer"
End If
Loop
Close #6
End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdHighLow_Click()
Dim strName As String, intScore As Integer, intTheNumH As Integer, intTheNumL As Integer
txths.Text = Str(intTheNumH)
intTheNumH = CInt(intScore)
txtls.Text = Str(intTheNumL)
intTheNumL = CInt(intScore)
txtln.Text = strName
txthn.Text = strName
Open "C:\Documents and Settings\Administrator\Desktop\golfer.txt" For Input As #6
Do Until EOF(6)
Input #6, strName, intScore
If intTheNumH > 0 Then
intScore
End If
Loop
Close #6
End Sub

^^^^I Dont Know if I am on the right track for the CMD "High Low" button, if you could help out I would greatly appreciate it. Files are attached \/ \/ Peace

Hi Student101,

Your code was SO close to being finished that it took me all of 5 min to get it going. You were on the right track and everything was almost done.

Here is what I changed, I tried to comment as much as possible.

Private Sub cmdHighLow_Click()
Dim strName As String, intScore As Integer, intTheNumH As Integer, intTheNumL As Integer

'New Dim's
Dim CurHighScore As Integer
Dim CurLowScore As Integer
Dim CurHighPlayer As String
Dim CurLowPlayer As String

'Can't use these here since the values are not set yet.
'txths.Text = Str(intTheNumH)
'intTheNumH = CInt(intScore)
'txtls.Text = Str(intTheNumL)
'intTheNumL = CInt(intScore)
'txtln.Text = strName
'txthn.Text = strName

'A good habit to take is NOT to hardcode paths, use the App.Path
'property to find out where the Application is currently running.
Open App.Path & "\golfer.txt" For Input As #6

'Read the first line of the file and set this to be both High and
'Low scores, this is true since we've only read one line
Input #6, strName, intScore
CurHighScore = intScore
CurLowScore = intScore
CurHighPlayer = strName
CurLowPlayer = strName

Do Until EOF(6)
    Input #6, strName, intScore
    If intScore > CurHighScore Then
        'If this player's score is higher than the current
        'high score, set the high values
        CurHighScore = intScore
        CurHighPlayer = strName
    ElseIf intScore < CurLowScore Then
        'If this player's score is lower than the current
        'low score, set the low values
        CurLowScore = intScore
        CurLowPlayer = strName
    End If
Loop
Close #6
'Display the found values
txths.Text = Str(CurHighScore)
intTheNumH = CInt(intScore)
txtls.Text = Str(CurLowScore)
intTheNumL = CInt(intScore)
txtln.Text = CurLowPlayer
txthn.Text = CurHighPlayer
End Sub

As you can see there was not much to do. Also, as a suggestion for your own sanity down the road, take the habit of using App.Path for paths related to where your application is located. You can see how to use it in the Open statement.

Have fun and good luck

Yomet

thnks man, im bout to go try this out. Peace

Hey Student101,

Did it work out to your linking? Just want to get some news. If it solved your problem just mark the thread as solved and, Please, add to my Reputation.

Thx

Yomet

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.