BBC BASIC for Windows
Programming >> BBC BASIC language >> 'Bad use of array' Error http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1373558240 'Bad use of array' Error
Post by Matt on Jul 11th, 2013, 3:57pm
Hi,
I have these lines in a PROC in my program:
... FOR R% = 0 TO IndexTop% IF R% <> recno% THEN PTR#F% = Index%(R%) ...
R% is a local variable for the loop. IndexTop% is global variable for the last indexed record. recno% is the passed reference perameter. F% is the local file cannel number. And most importantly: Index%() is a global array containing the indexes to records set at start up to 64k elements.
In my tests IndexTop% does not get above 10 and R% does not go below zero. Nowhere else in the PROC, or subroutines that are used within it, changes the value of R%. I even put in a PRINT R% just before the PTR# line, and it never moves outside these values.
However, occationally, I get the 'Bad use of array' error come up, even when I repeat a procedure whilst running the program that previously worked.
The help does not suggest anything that might be helpful in determining the problem. I've checked the memory available at the appropriate time, and there is plenty.
Is there any other reason that this could produce this error that I am unaware of, or can you suggest other tests that I might try in order to locate the problem.
Matt
Re: 'Bad use of array' Error
Post by admin on Jul 11th, 2013, 4:43pm
In my tests IndexTop% does not get above 10 and R% does not go below zero.... Is there any other reason that this could produce this error that I am unaware of
There's some confusion here. If an array subscript goes out of range the error that is generated is 'Bad subscript' (ERR=15) not 'Bad use of array' (ERR=14). There are various possible causes of the latter error, but if it's happening only intermittently I would be concerned that it might be heap corruption. If so the fault could be in a completely different part of the program.
In your situation, when the error occurs I would want to use the List Variables utility and possibly the Memory Monitor utility to check whether the array is still correctly defined on the heap.
Richard. Re: 'Bad use of array' Error
Post by Matt on Jul 11th, 2013, 9:02pm