Evaluating odd or even


mse3000

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.