Why does calculate button not work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mroberts50
    New Member
    • Sep 2010
    • 4

    Why does calculate button not work?

    I have to develop a programm for a race that is suppose to put the runners in first, second and third place. Everything works except my calculate button this is my code.Forgive me I am very new to this. Any advice

    Code:
    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
    Last edited by Stewart Ross; Feb 6 '11, 11:00 AM. Reason: Added [code]...[/code] tags round code segment and indented
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Your logic test at line 19 is incorrect and cannot do what you are expecting it to do. In particular, to test more than one variable you need to consider structuring your code like

    Code:
    IF (v1 < v2) AND (v2 < v3) THEN
    However, a single IF will not handle the logic you require for this exercise.

    You need to reconsider what your logic is. As this belongs to project work you are undertaking we cannot assist you further on this other than to point out the area in which your mistake arises.

    -Stewart

    PS in general programming languages behave very logically and in a highly-dependable way. When you say in your question that you think your code is correct, assuming that what you've written is correct can blind you to the very high probability that in fact it isn't!
    Last edited by Stewart Ross; Feb 6 '11, 11:13 AM.

    Comment

    • mroberts50
      New Member
      • Sep 2010
      • 4

      #3
      Thank you Stewart I truly appreciate your help. I will make the changes to this code and see what happens. I have worked with Access programming for so many years it blinds me to this VB stuff.

      Comment

      Working...