hexagon logo

Runtime script with inexplicable results...

I have a function in my scripts to calculate the runtime in seconds for a program, using the Timer value from windows, which returns the current time as seconds from midnight.

The blue code is my script run at the beginning of a part program. The red code is what is run at the end. (I've cut and pasted these sections from the scripts...they are too long.) In the event that a program runs through midnight, I have a section in the red code to correctly calculate runtime. I've tested this code in the excel editor while resetting my computer clock to 11:59 PM and running it through midnight, and it works. Unfortunately, this code does not work when running PC-DMIS through midnight. I get program times of more than 86400.

Any ideas why this is not calculating correctly only when run through PC-DMIS?

[COLOR="Blue"]Sub Main()

Dim BeforeTime As String
BeforeTime = Timer
BeforeTime = CLng(BeforeTime)

End Sub[/COLOR]

[COLOR="Red"]
Sub Main()

Dim Aftertime As String
Aftertime = Timer
Aftertime = CLng(Aftertime)
Dim RunTime As String

If Aftertime < BeforeTime Then
RunTime = (86400 - BeforeTime) + Aftertime
Else
RunTime = Aftertime - BeforeTime
End If

End Sub[/COLOR]
Parents
  • Ok, some more testing, and some more errors. Using Integer gives me an overflow error when it goes to grab the TIMER number from the computer. This does not happen in excel. I have yet to try to shorten the Timer number using Clng first, then assign it to an integer.

    I put parentheses all around my functions, just in case. I had a part run through midnight on Friday and guess what? It's a negative number now! Ex. The start of the program was 86000 seconds from midnight. The end of the program was 1000 seconds from midnight on the next day. The correct calculation would be a runtime of 1400 seconds.

    Previously this would have given me the result of 87000 seconds. Now it gives -85000 as the result. Angry

    So, continuing forward, I will try to get this working with integers, and test it then. Thanks for the help guys.
Reply
  • Ok, some more testing, and some more errors. Using Integer gives me an overflow error when it goes to grab the TIMER number from the computer. This does not happen in excel. I have yet to try to shorten the Timer number using Clng first, then assign it to an integer.

    I put parentheses all around my functions, just in case. I had a part run through midnight on Friday and guess what? It's a negative number now! Ex. The start of the program was 86000 seconds from midnight. The end of the program was 1000 seconds from midnight on the next day. The correct calculation would be a runtime of 1400 seconds.

    Previously this would have given me the result of 87000 seconds. Now it gives -85000 as the result. Angry

    So, continuing forward, I will try to get this working with integers, and test it then. Thanks for the help guys.
Children
No Data