mse3000 Posted September 2, 2010 Share Posted September 2, 2010 Just a quick question. I'm sure I have read on here before you can evaluate a function to be true or false dependant on whether the outcome is an odd or even integer. Can't seem to find it again though. Am I right in thinking this was true? Just wanting to run a machine forwards or backwards depending on the day of the month to avoid excessive wear in either direction. Regards, Mark Link to comment Share on other sites More sharing options...
AzeoTech Posted September 2, 2010 Share Posted September 2, 2010 Sure, just use modulus: x % 2 if it returns 1, then its odd, if it returns 0 its even. Note that if x needs to be an integer. Link to comment Share on other sites More sharing options...
mse3000 Posted September 3, 2010 Author Share Posted September 3, 2010 Ideal, can you please point out my error in the following expression though. Just trying it out using minutes but my variable just shows as blank. (FormatDateTime("%M",SysTime())) % 2 If I take off the outer brackets and drop the "%2" the current minute is displayed as an integer value, so what am I missing? Obviously something simple. Many Thanks. Mark Link to comment Share on other sites More sharing options...
AzeoTech Posted September 3, 2010 Share Posted September 3, 2010 That is because FormatDateTime() returns a string and you can't do math on a string. Well, you can, you can use + to concatenate strings, but none of the other operators work. So, you either need to wrap your formatdatetime() inside a strtodouble() function call: strToDouble(formatDateTime("%M",sysTime())) % 2 or, use math instead of formatdatetime() to determine what minute it is. I recommend only using formatDateTime to extract things like what month it is, that are hard to calculate. Calculating the minute of the hour, hour of the day, minute of the day, etc is quite easy using math: Minute of the hour: floor(systime() % 3600 / 60) Link to comment Share on other sites More sharing options...
mse3000 Posted September 7, 2010 Author Share Posted September 7, 2010 That is ideal, thankyou very much! As ever, excellent after sales support! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.