Menu

For-Next loop reports errors

Help
Paul Haug
2017-03-13
2017-03-13
  • Paul Haug

    Paul Haug - 2017-03-13

    This simple code is giving me fits. Even the led blink sample code from this forum gives me the same errors.
    Whats going on here ? This so simple it blows my mind, how I could not fix this ??

    -----------The error msg on compiling ------------------------
    Error: for Start value is too big for the Counter
    Error: for End value is too big for the Counter
    Error: Missing operand, before +


    .
    .
    .
    #chip 16F886
    #option explicit
    ;--------------------Just for testing------------------------------------
    #define testlp
    '
    #define DtoAClock PORTc.4 'pin 15
    #define DtoADir PORTc.5 'pin 16
    #define ADdata PORTb
    'Set port directions
    DIR DtoAClock OUT ;pin 15
    DIR DtoADir OUT ;pin 16
    ;Set port b direction
    DIR ADdata OUT ;pins 21 lsb - 28 msb

    dim testlp as word
    ;----------------------------------------------------

    do forever
    wait 500 ms
    For testlp = 1 to 55
    set DtoAClock on ;pin 15
    wait 3 ms
    set DtoAClock off
    wait 6 ms
    Next
    Loop

     

    Last edit: Paul Haug 2017-03-13
  • jackjames

    jackjames - 2017-03-13

    Try to put 'Next testlp' and not only 'next'

     
  • Marc in the Dark

    You have #define testlp at the top but not defined as anything. I remove it and it compiles fine.

     
  • William Roth

    William Roth - 2017-03-13

    You cannot #define something as a constant and then later DIM it as a variable.

    Remember, if the value needs to change (as in the for next loop) then do not use #define.

    General Rule: #define is for constants (non-changing values)
    DIM is for Variables (changing values)

     
  • Paul Haug

    Paul Haug - 2017-03-13

    Thanks guys, problem solved. William's explanation of why it didn't work is perfect Need to add that to my notes.
    Paul

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.