Min/max

oracacle

Senior Member
While writing some new code for a project modification I attempted:

Code:
inc b32 max 60
this gives a syntax error
however this does not:

Code:
let b32 = b32 + 1 max 60
I quick test without the max command show they are the same size, and from what I understand are the same after the programme is compiled. is there any reason why the editor can not accept the max with the inc command, seems a little odd when both would read the same after compiling

here the code snipet as it currently stands

Code:
      [color=Blue]do
            gosub [/color][color=Black]scancol                             [/color][color=Green]'check for user input
            [/color][color=Blue]if [/color][color=Purple]slct [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then                          [/color][color=Green]'shutter delay increase
                  [/color][color=Blue]let [/color][color=Purple]delay [/color][color=DarkCyan]= [/color][color=Purple]delay [/color][color=DarkCyan]+ [/color][color=Navy]1 [/color][color=DarkCyan]max [/color][color=Navy]60        [/color][color=Green]'allow a max of 60 sec
            [/color][color=Blue]else if [/color][color=Purple]slct [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then                     [/color][color=Green]'shutter delay decrease
                  [/color][color=Blue]let [/color][color=Purple]delay [/color][color=DarkCyan]= [/color][color=Purple]delay [/color][color=DarkCyan]- [/color][color=Navy]1 [/color][color=DarkCyan]min [/color][color=Navy]1         [/color][color=Green]'allow min of 1 sec
            [/color][color=Blue]else if [/color][color=Purple]slct [/color][color=DarkCyan]= [/color][color=Navy]3 [/color][color=Blue]then                     [/color][color=Green]'check for enable/disable of shutter timer
                  [/color][color=Blue]gosub [/color][color=Black]flagdelay
            [/color][color=Blue]else if [/color][color=Purple]slct [/color][color=DarkCyan]= [/color][color=Navy]5 [/color][color=Blue]then                     [/color][color=Green]'check for accepting settings
                  [/color][color=Blue]exit
            end if
            pause [/color][color=Navy]50                                  [/color][color=Green]'debounce delay
      [/color][color=Blue]loop[/color]
 

hippy

Technical Support
Staff member
It is simply the way the INC statement is defined; it can have a single variable parameter and that is it. I don't think anyone envisaged an INC or DEC command including further mathematical operations, but we can add that suggestion for consideration.

The code generated for "INC b32 : b32 = b32 MAX 60" and "LET b32 = b32 + 1 MAX 60" may appear to be the same based on bytes of code used but this is simply an anomaly of how tokens are encoded and counted. The two do generate different code of slightly different size; the second being shorter.
 

oracacle

Senior Member
fair enough, I am currently using the second one without issue. it just seemed strange at the time as it would be an ideal situation for the use of min/max after an inc/dec command
 

hippy

Technical Support
Staff member
One option to keep the code simpler if incrementing and decrementing with limits in a lot of places would be to create macros or define the code to do that ...

Code:
#Define Increment(var,maximum) var = var + 1 Max maximum

For b0 = 1 To 10
  Increment(b32,5)
  SerTxd( #b32, " ")
Next
 

oracacle

Senior Member
its only in that spot for that variable, its to alter the delay time before opening the shutter on a camera. I am still in 2 minds on weather I am going to use a pause of some length, which is then looped, or use timer. for that reason the code is subject to change, specially if some functions change or if I do like I have done for some increases and decrease which is when overflow or underflow is detected (ie if b32 = 61 then b32 = 1).

I must say I have never used macros, I reckon I am a little old school and prefer to call a sub procedure which can be in a include file - which incidentally I do use.
 
Top