syntax help

manuka

Senior Member
Am I reading this right? Do you mean that b12 has to be within ±1 of b7 to trigger the loop to "main" condition?
 

MikeGyver

Senior Member
For example:

b7 = 25
if b12 = 24-26 then goto main


Basically just giving me a bit of hysterisis in either direction (as opposed to me just saying "if b12 = b7 then goto main" )

I have a 7 segment display rapidly switching between 2 adjacent values, so a bit of hysterisis should fix this
 

hippy

Ex-Staff (retired)
You need to use two temporary variables (b0 and b1 in this exmple ) ...

Code:
b7 = [i]value[/i]
b0 = b7-1
b1 = b7+1
If b12 >= b0 And b12 <= b1 Then
  Gosub DoSomething
End If
You can also use one variable split that over two tests ...

Code:
b7 = [i]value[/i]
b0 = b7-1
If b12 >= b0  Then
  b0 = b7+1
  If b12 <= b0 Then
    Gosub DoSomething
  End If
End If
You'll need to handle the case when b7 = 0 and b7 = 255 specifically ( 0-1 = 255, 255+1 = 0).

You could also probably do something by determining the difference itself ( ie, b0 = b12-b7 ) and acting on that.
 
Last edited:

kevrus

New Member
You'll need to handle the case when b7 = 0 and b7 = 255 specifically ( 0-1 = 255, 255+1 = 0).
If you know the range that you are displaying, I think you could use the 'max' 'min' facility to avoid the above overflow (is that the right terminology?) situation

i.e.
Code:
b7 = value  
b0 = b7-1 min 5                  'sets minimum value to 5(change this number to suit)
b1 = b7+1 max 250                'sets maximum value to 250(change this number to suit)
If b12 >= b0 And b12 <= b1 Then
  Gosub DoSomething
 End If
 

westaust55

Moderator
Code:
b7 = value  
b0 = b7-1 min 5                  'sets minimum value to 5(change this number to suit)
b1 = b7+1 max 250                'sets maximum value to 250(change this number to suit)
If b12 >= b0 And b12 <= b1 Then
  Gosub DoSomething
 End If
b0 = b7-1 min 5 will not work as suggested, or as hippy proposed over the full available range (0 to 255), because the line is executed left to right with no precedence and min acts as a limiting fucntion, not the lower of two values.

first we get b7 - 1 so if b7 = 0 then the result is 255 as roll over has occurred as hippy mentioned
next we use min so b0 = 255 min 5 = 255

but this would work:
b0 = b7 min 1 -1
b1 = b7 max 254 +1


Edit:
as mentioned above the min and max are limiting functions. So,
b0 = b7 min 5 will return the higher value of b7 and 5.

and
b1 = b7 max 250 will return the lower value of b7 and 250
 
Last edited:

kevrus

New Member
Westaust is right.
I rushed the post and wrote it without thinking...moral, read my posts,laugh at them, then totally disregard them as the ramblings of a donut!!
 

hippy

Ex-Staff (retired)
@ westaust55 : That's the best option. Thanks.

@ kevrus : Not a complete "donut", you were on the right track. This wrap-round, lack of negative numbers can get quite complicated, easy to forget and can throw a spanner in the works. My comment about =0 or =255 was only added after I'd first posted and suddenly remembered :)
 
Top