Compacting repetitive code with FOR/NEXT?
xanatos
Posts: 1,120
Hi there,
I have to have 10 iterations of the following code sections (they are NOT together, just shown here for convenience):
····· SEROUT TX, Baud, [noparse][[/noparse]"!NB0R51"]·········· ' Send Command To Read Variable 51 on PINK (packdate2 exp time storage)
······SEROUT TX, Baud, [noparse][[/noparse]"!NB0W51:0000000000", CLS]· ' Wipe out time entry in data storage
The issue revolves around needing to change the PINK variable name in each iteration (NB0R51, NB0R52, NB0R53, etc).· Since I am running out of EEPROM space, and yet so near completion without having to use another program slot for the function, what I am wondering is if I can repeat this code using a FOR/NEXT loop, and·replace the actual string "!NB0RXX" with a variable, something along the lines of:
···· IF S = 1 THEN
········· TXSTR = "!NB0R51"
···· ELSEIF S = 2 THEN
········· TXSTR = "!NB0R52"
···· ELSEIF......
I'm asking this, rather than just trying it, as the development environment can no longer support such an experiment for a variety of reasons beyond the scope of this post.· I'm hoping that someone can answer without my having to resort to a significant risk to a component... :-)
Thanks very much!!!!
Dave
·
I have to have 10 iterations of the following code sections (they are NOT together, just shown here for convenience):
····· SEROUT TX, Baud, [noparse][[/noparse]"!NB0R51"]·········· ' Send Command To Read Variable 51 on PINK (packdate2 exp time storage)
······SEROUT TX, Baud, [noparse][[/noparse]"!NB0W51:0000000000", CLS]· ' Wipe out time entry in data storage
The issue revolves around needing to change the PINK variable name in each iteration (NB0R51, NB0R52, NB0R53, etc).· Since I am running out of EEPROM space, and yet so near completion without having to use another program slot for the function, what I am wondering is if I can repeat this code using a FOR/NEXT loop, and·replace the actual string "!NB0RXX" with a variable, something along the lines of:
···· IF S = 1 THEN
········· TXSTR = "!NB0R51"
···· ELSEIF S = 2 THEN
········· TXSTR = "!NB0R52"
···· ELSEIF......
I'm asking this, rather than just trying it, as the development environment can no longer support such an experiment for a variety of reasons beyond the scope of this post.· I'm hoping that someone can answer without my having to resort to a significant risk to a component... :-)
Thanks very much!!!!
Dave
·
Comments
···· SEROUT TX, Baud, [noparse][[/noparse]"!NB0R", DEC S]·· ' If S = 51, result posts !NB0R51 to the PINK, and teh variables come back as they should.
Dave
Dave