BBC BASIC for Windows
« 'Bad use of array' Error »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:46pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: 'Bad use of array' Error  (Read 360 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 'Bad use of array' Error
« Thread started 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: 'Bad use of array' Error
« Reply #1 on: Jul 11th, 2013, 4:43pm »

on Jul 11th, 2013, 3:57pm, Matt wrote:
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.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: 'Bad use of array' Error
« Reply #2 on: Jul 11th, 2013, 9:02pm »

Ok. Thanks. I'll try those.

Matt
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls