TimeDiff interval check

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
Enricoys
Newbie
Posts: 12
Joined: Mon Jan 06, 2014 1:18 pm

TimeDiff interval check

Post by Enricoys » Mon Mar 23, 2020 4:09 pm

Over the last months I noticed a very strange behaviour with on one of my large scripts. I couldn't find the problem because it was each time something else what happened, however it looked like that was caused by a memory issue. Now I found the problem. Somewhere in the script I used a variable name 's' which got the value 'Germany'. Much deeper in the code I used a few times the TimeDiff function making that the problem started. This is of course caused by the reason that TimeDiff uses 's' for the interval check in seconds and now this 's' became 'Germany'. The program didn't generate a error message and even the first few calls of TimeDiff worked normal, but after then the problems started. It is now solved by changing my variable name 's' in something else and to be sure I also pass the interval to timediff now as {"S"} instead of just S. I observed that the TimeDiff function can cause some severe (memory) issues if the wrong interval parameter is passed. I want to suggest that you would first check the interval parameter in the TimeDiff function and reply with a error message it it does not match 'S', 'M' or 'H'.

User avatar
Grovkillen
Automation Wizard
Posts: 498
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: TimeDiff interval check

Post by Grovkillen » Mon Mar 23, 2020 5:30 pm

Those variable names made me pull my hair as well. It's a nice feature though so I now always add the sub routine name as the prefix. I.e.

SRT>TimeCheck
Let>TIMECHECK_S=blabla
END>TimeCheck
Let>ME=%Script%

Running: 15.0.9
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 697
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: TimeDiff interval check

Post by Dorian (MJT support) » Tue Mar 24, 2020 12:09 am

Single letter variable assignments should be avoided, and this is one very good reason why. We see this quite often when people are reading from Excel and they'll assign a variable according to the column they're reading. Col_S would be a lot less dangerous than simply S, for example.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts