subtracting times and passing to a function causes problems.

so basically starttime and endtime are logged as a process is happening and ending then minused in the following line.

put “Format Time”.Get(endTime-startTime) into item moduleNumber of runTime

Normally the “Format Time”.Get() functions will get the difference between the two times as seconds. so 665.1234455 but lately and more often now it will get like 12:34 and then fail because it is expecting a number. Any ideas on what might be causing this random behavior to happen. It used to be a very rare bug that would happen but now it is happening all the time.

What does your Format Time script look like? Does it override “get” (which is an existing command in SenseTalk)?

It looks like this and fails on the second line.

to Get param
put param rounded to 0 places into param

To fix this I just made a couple of global variables and a check so it looks like this now and can deal with the time being sent in both ways.

to Get param
global starttime
global endtime
log param
–to deal with a random bug where the time is not represented in seconds properly
If param is not a number then
log “endtime:” & endtime
log “starttime:” & starttime
set param to endtime - starttime
end if

put param rounded to 0 places into param
set the numberFormat to "00"

A bit of explanation about time values may be helpful here.

A time value in SenseTalk is (internally) a number, that usually has a display format associated with it. If you add or subtract a number from that value, it will retain its format. This lets you do things like this:

put the long date into dueDate
add 1 week to dueDate
put dueDate -- displays "Tuesday, January 27, 2009"

Here, the new dueDate is displayed in the long date format that was specified in the first line, although the actual value has been changed by a week.

On the other hand, if you subtract one time value from another you should simply get the difference between them (as a number of seconds), which you can see by extending the above example:

put the date into originalDate
subtract originalDate from dueDate
put dueDate -- displays "604800" (which is 1 week)

In your case, I’m guessing that in some parts of your code you borrowed from some old examples (that can still be found here and there on this forum) from the days when we recommended using “the long seconds” to time an operation. Nowadays we suggest that you simply use “the time”. Although this will display a value that only shows the hour and minute, internally it is a very precise value down to a small fraction of a second.

What I’m getting to with this long explanation is that if you mix the two styles, using both “the long seconds” and “the time”, you can get what appears to be a very different value. For example:

put the long seconds into startTime
wait a second
put the time into endTime

put endTime - startTime into elapsed
put elapsed

This example displays “05:00 PM” for me (this will vary depending on what time zone you are in) which clearly doesn’t look much like the elapsed time of a one-second operation! Changing the first line to “put the time into startTime” will display a number instead, like 1.000301 (one second plus the length of time it took to execute a couple of commands).

Hopefully this gives you a better understanding of why sometimes you may see a value that’s formatted as a time (like “12:34”) and sometimes as a number.

However, this doesn’t explain why you’re getting a “not a number” error. Although they look different, the value obtained either way should be a number. In my tests it worked fine to do something like “put elapsed rounded to 0 places” (which displays “1” as expected). If you continue to have trouble, you may need to post more details about exactly how you’re calling the function so we can see just what’s going on.