"Min 1" when a variable starts as 0

smeagol

Member
Is this a bug or is this the way it is supposes to work?

Code:
[color=Blue]elseif [/color][color=Black]buttondown [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
            [/color][color=Black]IntervalSeconds [/color][color=DarkCyan]= [/color][color=Black]IntervalSeconds [/color][color=DarkCyan]- [/color][color=Navy]1 [/color][color=DarkCyan]min [/color][color=Navy]1[/color]
I've only posted the relevent section of code but I'm confident there is nothing else interfering. It is part of a small routine to increased and decrease a variable with switches for Up and Down.

buttondown is an input switch ( It works fine)
IntervalSeconds is declared as a Word variable (w9)

on first run (intervalseconds will be 0 it's not actively set to anything) if an input of down is received IntervalSeconds decreases and registers as 65535, this is what I would expect to happen without the "min" command at the end of the line. So the min command is not doing anything.

The min command works as expected if I first increase intervalseconds to 1 or above.

To my, sleep deprived at the moment, mind I would expect that if min see's a value of 0 it should increase it to 1 in this case.
 

smeagol

Member
DOH.

I've just realised my error, decreasing 0 gives 65535 which is > 0 so the "min 1" has no effect.

Moral, don't try and write stuff when you have just finished 60 hours working in 5 days at 06:00 this morning and have had about 2 hours sleep.

Sorry for the daft post.
 

AllyCat

Senior Member
Hi,

Well done for quickly spotting that well-known "gotcha" (which has probably caught most of us at some time).

The "fix" is simply to modify the syntax a little:
Code:
IntervalSeconds = IntervalSeconds min 1 - 1
Cheers, Alan.
 
Top