Computing.Net > Forums > Programming > Visual Basic Project Help Needed...

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Visual Basic Project Help Needed...

Reply to Message Icon

Name: Imyewneek
Date: October 29, 2008 at 11:12:19 Pacific
OS: Dell, Windows Vista
CPU/Ram: Unsure
Product: Unsure
Comment:

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 If

End 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!!




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 29, 2008 at 15:47:17 Pacific
Reply:

If txtrunner1finish < txtrunner2finish < txtrunner3finish Then

This evaluates to either
If -1 < txtrunner3finish Then

Or
If 0 < txtrunner3finish Then

Instead, write this:
If txtrunner1finish < txtrunner2finish And txtrunner2finish < txtrunner3finish Then

Also:

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

-1
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Visual Basic Project Help Needed...

Visual Basic Parallel Port www.computing.net/answers/programming/visual-basic-parallel-port/6529.html

Visual Basic: Is there a learner's thing www.computing.net/answers/programming/visual-basic-is-there-a-learners-thing/924.html

Visual Basic IF help www.computing.net/answers/programming/visual-basic-if-help/15162.html