junkie_ball
Member
- Joined
- Mar 25, 2010
- Messages
- 19
- Programming Experience
- 1-3
Hi,
This is my first post here (of many i hope). I been dabbling with VB on and off for a few years now i started with VB6 and now using VB.Net. I'm trying to generate a simple average pace calculator. I have coded the calculator to a stage where it seems to work although on testing it i have noted my average pace rounding seems to vary slightly from others online. Although i have also note different calculators online seem to vary from each other.
I have used the .tostring("0.##") as a means of converting my calculation back to actual time rather than a decimal. Is this the correct method or is there a better way?
I have posted the code below. Please excuse it if the code is not as neat as it could be but like i start i'm still a novice.
This is my first post here (of many i hope). I been dabbling with VB on and off for a few years now i started with VB6 and now using VB.Net. I'm trying to generate a simple average pace calculator. I have coded the calculator to a stage where it seems to work although on testing it i have noted my average pace rounding seems to vary slightly from others online. Although i have also note different calculators online seem to vary from each other.
I have used the .tostring("0.##") as a means of converting my calculation back to actual time rather than a decimal. Is this the correct method or is there a better way?
I have posted the code below. Please excuse it if the code is not as neat as it could be but like i start i'm still a novice.
VB.NET:
Dim Hours, Mins, Secs As Integer
Dim Distance, Pace As Decimal
Try
Distance = CDec(txtDistance.Text)
'Ensures all time fields have data
If txtHrs.Text = "" Or txtMins.Text = "" Or txtSecs.Text = "" Then
MsgBox("Please enter a time to calculate average pace from", MsgBoxStyle.Information, "Average Pace Calculator")
Else
Try
Hours = CInt(txtHrs.Text)
Mins = CInt(txtMins.Text)
Secs = CInt(txtSecs.Text)
If cmbDistanceUnit.Text = "Mile" Then
Pace = ((Hours * 60) + (Mins) + (Secs / 60)) / Distance
txtPace.Text = Pace.ToString("0.##") & " Per Mile"
ElseIf cmbDistanceUnit.Text = "Kilometer" Then
Pace = ((Hours * 60) + (Mins) + (Secs / 60)) / Distance
txtPace.Text = Pace.ToString("0.##") & " Per Kilometer"
Else
MsgBox("Please Select Kilometers or Miles", MsgBoxStyle.Information, "Average Pace Calculator")
End If
Catch ex As Exception
MsgBox("Please enter a valid time", MsgBoxStyle.Information, "Average Pace Calculator")
End Try
End If
Catch ex As Exception
MsgBox("Please enter a valid distance", MsgBoxStyle.Information, "Average Pace Calculator")
End Try