|
-
Jun 8th, 2010, 11:07 AM
#1
Thread Starter
PowerPoster
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]
-
Jun 8th, 2010, 12:21 PM
#2
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
-
Jun 8th, 2010, 12:55 PM
#3
Thread Starter
PowerPoster
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]
-
Jun 8th, 2010, 01:05 PM
#4
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|