Using arrays

I was implementing a flying sample routine on a tstat10 and I believe I have identified a problem accessing arrays. after trying severalvariations I believe the problem lies with pushing and pulling data from arrays.
Here is the program. I should sample the temperature every 2 seconds and calculate an average. The only code that works does not use arrays.

10 REM REQUIRES ARRAY 2 AND ARRAY 3 TO BE LENGTH ARRAYSIZE
20 ARRAYSIZE = 10
30 IF INTERVAL ( 00:00:02 ) THEN SAMPLEINDX = SAMPLEINDX + 1
40 IF SAMPLEINDX >= ARRAYSIZE THEN SAMPLEINDX = 0
50 REM USING CALCULATED INDEXING
60 IF SAMPLEINDX <> OLDSAMPLEINDX THEN OLDSAMPLEINDX = SAMPLEINDX , AY2[SAMPLEINDX] = IN9
70 REM USING FIXED INDEXING
80 IF+ SAMPLEINDX = 0 THEN AY3[0] = IN9 , VAR70 = IN9
90 IF+ SAMPLEINDX = 1 THEN AY3[1] = IN9 , VAR71 = IN9
100 IF+ SAMPLEINDX = 2 THEN AY3[2] = IN9 , VAR72 = IN9
110 IF+ SAMPLEINDX = 3 THEN AY3[3] = IN9 , VAR73 = IN9
120 IF+ SAMPLEINDX = 4 THEN AY3[4] = IN9 , VAR74 = IN9
130 IF+ SAMPLEINDX = 5 THEN AY3[5] = IN9 , VAR75 = IN9
140 IF+ SAMPLEINDX = 6 THEN AY3[6] = IN9 , VAR76 = IN9
150 IF+ SAMPLEINDX = 7 THEN AY3[7] = IN9 , VAR77 = IN9
160 IF+ SAMPLEINDX = 8 THEN AY3[8] = IN9 , VAR78 = IN9
170 IF+ SAMPLEINDX = 9 THEN AY3[9] = IN9 , VAR79 = IN9
180 REM AVERAGING LOOP
190 TOTAL = 0
200 TOTAL2 = 0
210 FOR X = 0 TO ARRAYSIZE - 1 STEP 1
220 TOTAL = TOTAL + AY2
230 TOTAL2 = TOTAL2 + AY3
240 NEXT X
250 VAR100 = TOTAL / ARRAYSIZE
260 VAR101 = TOTAL2 / ARRAYSIZE
270 VAR102 = ( AY3[0] + AY3[1] + AY3[2] + AY3[3] + AY3[4] + AY3[5] + AY3[6] + AY3[7] + AY3[8] + AY3[9] ) / 10
280 VAR103 = ( VAR70 + VAR71 + VAR72 + VAR73 + VAR74 + VAR75 + VAR76 + VAR77 + VAR78 + VAR79 ) / 10
290 REM DEBUG STUFF
300 VAR90 = AY2[0]
310 VAR91 = AY2[1]
320 VAR92 = AY2[2]
330 VAR93 = AY2[3]
340 VAR94 = AY2[4]
350 VAR95 = AY2[5]
360 VAR96 = AY2[6]
370 VAR97 = AY2[7]
380 VAR98 = AY2[8]
390 VAR99 = AY2[9]
400 VAR80 = AY3[0]
410 VAR81 = AY3[1]
420 VAR82 = AY3[2]
430 VAR83 = AY3[3]
440 VAR84 = AY3[4]
450 VAR85 = AY3[5]
460 VAR86 = AY3[6]
470 VAR87 = AY3[7]
480 VAR88 = AY3[8]
490 VAR89 = AY3[9]

I would expect variables 100, 101, 102 and 103 all to contain the same value.

Arrays are an area where we can definitely do with some improvements. Lijun will study this and report back first thing Monday.

Our T3000 programming system has indeed not been sufficiently tested for array applications, which has led to the issue you encountered. For now, we recommend that you use non-array programming methods.

Additionally, it appears that there might be a copying error in your code on lines 230 and 240. They should be written as follows:

230   TOTAL = TOTAL + AY2[X]
240   TOTAL2 = TOTAL2 + AY3[X]

Lijun will spend some time on arrays, we need good features and a method to do loops Lijun.

FOR i = 1 TO 10
’ Perform some action, for example, increment a variable
total = total + i
NEXT i