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. Thanks in advance ;)
Sub Main() 'Declaring variables used in the program Dim distance As Integer Dim time, totaldistance, totaltime, average As Single
'Loop that calls the following functions to display the message box 6 times and change the day For i = 1 To 6 distance = Val(InputBox("Enter the km travelled on day" + Str$(i))) If IsNumeric(distance) = False Then MsgBox ("please enter a number") End If
time = Val(InputBox("Enter the minutes taken on day" + Str$(i))) If IsNumeric(time) = False Then MsgBox ("please enter a number") End If
totaldistance = totaldistance + dist totaltime = totaltime + time Next i
'Calculates and displays the total time, distance and kmph MsgBox ("The total distance travelled over the week =" + Str$(totaldistance) + "kms") MsgBox ("The total time taken running over the week =" + Str$(totaltime) + " minutes") average = totaldistance / totaltime * 60 MsgBox ("Your average speed is =" + Str$(average) + " kmph") End Sub [/vb6][code=vb6]
Sub Main()
'Declaring variables used in the program
Dim distance As Integer
Dim time, totaldistance, totaltime, average As Single
'Loop that calls the following functions to display the message box 6 times and change the day
For i = 1 To 6
distance = Val(InputBox("Enter the km travelled on day" + Str$(i)))
If IsNumeric(distance) = False Then
MsgBox ("please enter a number")
End If
time = Val(InputBox("Enter the minutes taken on day" + Str$(i)))
If IsNumeric(time) = False Then
MsgBox ("please enter a number")
End If
totaldistance = totaldistance + dist
totaltime = totaltime + time
Next i
'Calculates and displays the total time, distance and kmph
MsgBox ("The total distance travelled over the week =" + Str$(totaldistance) + "kms")
MsgBox ("The total time taken running over the week =" + Str$(totaltime) + " minutes")
average = totaldistance / totaltime * 60
MsgBox ("Your average speed is =" + Str$(average) + " kmph")
End Sub [/vb6]