Calculating speed using distance/time problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yilmaz
    New Member
    • Feb 2015
    • 1

    Calculating speed using distance/time problem

    hi
    I recently coded a program which displays the timespan between 2 different times. I used the DateTime function to do this but now i can't calculate the speed as you cannot use DateTime in division, is there another function i should use?
    This is my code so far:
    Code:
     
    Public Class Form1
        Dim starttime As DateTime
        Dim endtime As DateTime
        Dim timetaken As TimeSpan
        Dim registration As String
        Dim Distance As Integer
        Dim speed As Decimal
    
    
        Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
            starttime = DateTime.Parse(txtStart.Text)
            endtime = DateTime.Parse(txtEnd.Text)
            timetaken = endtime - starttime
            registration = txtReg.Text
            Distance = 500
    
            speed = Distance / timetaken
    
        End Sub
    End Class
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    You could use DateTime.Ticks

    But you should verify that starttime and endtime are on the same date.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      I believe you're in the wrong forum. That looks like VB.Net code, and this is the VB6 (very old pre-dotnet version) forum. That's probably why you haven't seen much of a response.

      Speaking strictly from a VB6 perspective, I would have suggested using the DateDiff() function to get the difference as a number of known units - most likely seconds. But I have no idea what the VB.Net equivalent would be. Perhaps a search for something like "datediff VB.Net equivalent" would be fruitful.

      Comment

      Working...