Shop OBEX P1 Docs P2 Docs Learn Events
VERY Odd code/variable behavior — Parallax Forums

VERY Odd code/variable behavior

xanatosxanatos Posts: 1,120
edited 2012-03-27 11:06 in BASIC Stamp
UPDATE: I rearranged the order of the VARs and put d NIB(6) last, and the problem disappeared. Am I misreferencing the array somehow?

Update #2... Uhm, gee, Dave. Yes, d(6) would be the 7th element of d, since you only specify 6, you're overwriting the next var, which is x, and then whichPump, so, yes, you are misreferencing your array variable... -- Sincerely, Dave. :-)

Hi there,

As usual, if something really odd can be found, it will be found in my code. Case in point: I have the following sections of code - VARs and the code in question:
d               VAR     Nib(6)          ' Mileage number holders

x               VAR     Byte            ' Ye olde GP counter var
whichPump       VAR     Nib             ' Pump actively being keyed for.

AND
  DEBUG "Before clearing the d(x)'s: ",DEC whichPump, CR

  FOR x = 1 TO 6
    d(x) = 0
  NEXT

  DEBUG "After clearing the d(x)'s: ",DEC whichPump, CR

Note that the code in this slot is very sparse and simple, what you see here is pretty much the only active area of concern to this question, which is: In the DEBUG window, when I run this code, I get these outputs:

Before clearing the d(x)'s: 1
After clearing the d(x)'s: 0

whichPump is set earlier in my program and is only used in LOOKUPS as in LOOKUP whichPump, [2, 5, 8, 13, 21...], x

x is a general purpose variable in my code. Something in that single for/next loop is clearing whichPump back to zero.

Any clues what I'm missing here?

It makes about as much sense to me as if I cleaned out my silverware drawer and my closet got emptied. There should be, as far as I know, no relationship between these things. I am utterly perplexed.

Thanks for your help,

Dave

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2012-03-26 19:00
    Don't Pbasic array indexes state at zero? So your loop should be 0 to 5 for a 6 nibble array?

    update: I think I was writing this during your update.
  • xanatosxanatos Posts: 1,120
    edited 2012-03-27 11:06
    :-) If you think I talk to myself on this board, you should hear me actually working here in my office! :-)

    Dave
Sign In or Register to comment.