Results 1 to 6 of 6

Thread: need help checking for number in vb6

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    8

    need help checking for number in vb6

    Hi guys i'm working on some code whereby the user inputs a distance and time they took spent running for days 1 to 6 and it works fine however I can't get it to display a message box if the user inputs letters instead of numbers. I've had a go at trying to do it and you can see my attempt in the code below and btw this is a module in case it helps.
    vb Code:
    1. Sub Main()
    2. 'Declaring variables used in the program
    3. Dim distance As Integer
    4. Dim time, totaldistance, totaltime, average As Single
    5.  
    6. 'Loop that calls the following functions to display the message box 6 times and change the day
    7. For i = 1 To 6
    8. distance = Val(InputBox("Enter the km travelled on day" + Str$(i)))
    9. If IsNumeric(distance) = False Then
    10. MsgBox ("please enter a number")
    11. End If
    12.  
    13. time = Val(InputBox("Enter the minutes taken on day" + Str$(i)))
    14. If IsNumeric(time) = False Then
    15. MsgBox ("please enter a number")
    16. End If
    17.  
    18. totaldistance = totaldistance + dist
    19. totaltime = totaltime + time
    20. Next i
    21.  
    22. 'Calculates and displays the total time, distance and kmph
    23. MsgBox ("The total distance travelled over the week =" + Str$(totaldistance) + "kms")
    24. MsgBox ("The total time taken running over the week =" + Str$(totaltime) + " minutes")
    25. average = totaldistance / totaltime * 60
    26. MsgBox ("Your average speed is =" + Str$(average) + " kmph")
    27. End Sub
    Last edited by Hack; Oct 29th, 2009 at 12:35 PM. Reason: Added Highlight Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width