Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey people.
I am in a beginning level Visual Basic Class and we are using the text "Starting out with Visual Basic 2008 4th Edition" by Tony Gaddis. My friend and I are really struggling with one of the projects which projects the result of a race.
We are running into issues in the coding where we can get the names to appear in order based on who ran the fastest. I attatched a picture of the form for you to look at and what I have for coding. Any combination I have tried just fails and nothing comes up when I hit the "calculate results" button.
We need the names in text boxes, the times in text boxes, and then the results to appear in labels.
Here is what I have so far in the coding for the calculate results button.... where are we going wrong??
Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
'Calculate who came in first, second and third place
Dim txtrunner1finish As Single
Dim txtrunner2finish As Single
Dim txtrunner3finish As Single'Copy the times into the variables
Try
txtrunner1finish = CSng(txtrunner1finish.ToString)
txtrunner2finish = CSng(txtrunner2finish.ToString)
txtrunner3finish = CSng(txtrunner3finish.ToString)Catch ex As Exception
MessageBox.Show("Time scores must be numeric.", "Error")
Return
End Try
'Calculate and display the winner
If txtrunner1finish < txtrunner2finish < txtrunner3finish Then
lblfirstresults.Text = txtrunner1finish
lblsecondresults.Text = txtrunner2finish
lblthirdresults.Text = txtrunner3finish
End IfEnd Sub
Any help would be most appreciated! I have a mental block when it comes to math normally so this is a struggle for me! Thank you!!

If txtrunner1finish < txtrunner2finish < txtrunner3finish Then
This evaluates to eitherIf -1 < txtrunner3finish Then
OrIf 0 < txtrunner3finish Then
Instead, write this:If txtrunner1finish < txtrunner2finish And txtrunner2finish < txtrunner3finish ThenAlso:
txtrunner1finish = CSng(txtrunner1finish.ToString)
txtrunner2finish = CSng(txtrunner2finish.ToString)
txtrunner3finish = CSng(txtrunner3finish.ToString)
All three will always be 0. Rename the txtrunnerXfinish to something like sngrunnerXfinish

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |