Results 1 to 4 of 4

Thread: Timespan issue

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Timespan issue

    Forgive me for being an idiot. But, I can't seem to get a timespan value in milliseconds. I'm sure it's something simple, but I can't see it.

    Code:
    If OneCounter(I) = 0 Then
          'determine cycle time
          cycletime(I) = CDate(TimeString).Subtract(CDate(cyclestarttime(I)))
                        '
           lineinfo = "STL|" & LineNumber.ToString & "|" & Now.ToString & "|" & (cycletime(I).TotalMilliseconds / 1000).ToString & "|" & linestate
    I am getting cycletime down to seconds, but the app needs milliseconds.
    Cycletime is defined as type timespan

    I am a VB6 guy trying to write a VS2008.NET app.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Timespan issue

    I'd look at TimeString and cyclestarttime(I) -- why are you using CDate on them? they should be datetime objects to begin with... if they are strings, then I'd suspect that you're losing your millisecond precision due to the conversion. Addotionally, if you are trying to time something, use the Stopwatch class... which will give you time elapsed values (incuding miliseconds)

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Timespan issue

    I tried the following changes

    Code:
                    If OneCounter(I) = 0 Then
                        'determine cycle time
                        cycletime(I) = (Date.Now).Subtract(cyclestarttime(I))
                        lineinfo = "STL|" & LineNumber.ToString & "|" & Now.ToString & "|" & (cycletime(I).TotalMilliseconds / 60000).ToString & "|" & linestate
                        If cycletime(I).TotalSeconds > 0 Then
                            td.SendLineInfo(lineinfo)
                        End If
                        OneCounter(I) = 1
                        'reset start time for cycle count
                        cyclestarttime(I) = CDate(Date.Now)
                    End If

    Now, instead of, say 20.0, I get 1056859200.103
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  4. #4

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Timespan issue

    I think I may have it. This bit of code seems to give me numbers that I might expect:

    Code:
                Dim lineinfo As String
                If linestate = 1 Then
                    'reset start time
                    line2Time(I) = Date.Now
                    If OneCounter(I) = 0 Then
                        'determine cycle time
                        cycletime(I) = Date.Now.Subtract(cyclestarttime(I))
                        lineinfo = "STL|" & LineNumber.ToString & "|" & Now.ToString & "|" & (cycletime(I).TotalMilliseconds / 1000).ToString & "|" & linestate
                        If cycletime(I).TotalSeconds > 0 Then
                            td.SendLineInfo(lineinfo)
                        End If
                        OneCounter(I) = 1
                        'reset start time for cycle count
                        cyclestarttime(I) = Date.Now
                    End If
                Else
                    'check to see if greater than 60 seconds
                    OneCounter(I) = 0
                    line2timespan = Date.Now.Subtract(line2Time(I))
                    If line2timespan.TotalSeconds > 60 Then
                        line2Time(I) = Date.Now 
                        'send a "down" record
                        lineinfo = "STL|" & LineNumber.ToString & "|" & Date.Now.ToString & "|" & "0" & "|" & linestate
                        td.SendLineInfo(lineinfo)
                        cyclestarttime(I) = Date.Now
                    End If
                End If
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

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