Shop OBEX P1 Docs P2 Docs Learn Events
Compacting repetitive code with FOR/NEXT? — Parallax Forums

Compacting repetitive code with FOR/NEXT?

xanatosxanatos Posts: 1,120
edited 2009-07-01 22:54 in BASIC Stamp
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




·

Comments

  • xanatosxanatos Posts: 1,120
    edited 2009-07-01 22:36
    Never mind - found a terminal emulator.... all set!· And the answer is, YES, it can be done.· For anyone intersted, here's the code:

    ···· 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
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-01 22:44
    If you ever change things so you need to use variables 0 through 9, you will need to use DEC2 instead of DEC.
  • xanatosxanatos Posts: 1,120
    edited 2009-07-01 22:54
    Good point, thanks!

    Dave
Sign In or Register to comment.