A Basic program -- missing array index?

In summary: CL(1), CW(1), ES(1), FR(1), LS(1), RS(1), SP(1), XX(1), Z1(1), Z2(1), Z3(1), Z5(1), Z6(1), Z7(1)In summary, the programmer tried to pass an integer array to a function that expects a pointer to the first object in the array. The compiler said there was an error because the variable on the right did not have an index. The programmer may have been using a different dialect of BASIC or a different compiler.
  • #1
Prophet
18
0
If someone can help me with this I'd be grateful. I've asked this question on other forums, gotten lots of views but no answer. It's no big deal but maybe someone has a solution.

I've have a program written in BASIC. I did not write the program and I have no way to contact the original programmer.

Here's the big problem. There are quite a few lines in the code like this one

NH(N) = NH

NH has been declared by

DIM NH(20)

but the variable on the right does not have an index and this makes the compiler unhappy. I originally suspected that whatever compiler the programmer was using had some sort of default index feature, probably 1 or 0. Lately I've begun to think that the programmer never did get it to run.
 
Technology news on Phys.org
  • #2
Hello Mr Prophet (or is it a first name ?)

Perhaps we can have a stab at the writer's original intention with a bit bigger chunk of source code ?
 
  • #3
What is the compiler saying exactly?

in most languages, passing an array is treated the same way as passing a pointer to the very first object in the array.
 
  • #4
Prophet said:
Lately I've begun to think that the programmer never did get it to run.

That is very possible. Some student wrote it part way got a new job or started a new semester and left it unfinished.
 
  • #5
Understanding other's programs is not an easy task. If the program is small, I would write it from scratch.
 
  • #6
newjerseyrunner said:
What is the compiler saying exactly?
Code:
posex.bas(97) error 72: Array access, index expected, before '='
                If S = 999 Or FS = 999 Then GoTo 840
                     ^
 
  • #7
BvU said:
with a bit bigger chunk of source code
I meant a bit more than one line...:smile:
Error 72 says you want to specify WHICH element of array S has to be compared with the number 999.
Perhaps at first S was an integer variable and has changed to an integer array without this routine being updated...
 
  • #8
I may be mistaken, it was a looooong time ago, but I think you may have been able to have distinct variables NH and NH().
Certainly NH%, NH!, NH# and NH$ would be distinct variables (integer, single, double and string) capable of holding four different values at the same time. Whether NH and NH() add more options, I'm not certain.

Edit: this comes from TRS80 Basic. There were many dialects of Basics. I think this would not have applied to the early MS Basics.
 
Last edited:
  • #9
BvU said:
Hello Mr Prophet (or is it a first name ?)
It's a surname. It's Scottish believe it or not.
 
  • #10
Prophet said:
If S = 999 Or FS = 999 Then GoTo 840
Is this sitting inside a loop ? (If so then show the loop code :smile: )
 
  • Like
Likes Nidum
  • #11
Merlin3189 said:
I may be mistaken, it was a looooong time ago, but I think you may have been able to have distinct variables NH and NH().
Certainly NH%, NH!, NH# and NH$ would be distinct variables (integer, single, double and string) capable of holding four different values at the same time. Whether NH and NH() add more options, I'm not certain.
I was thinking the same thing but didn't weigh in. It's sort of like different namespaces for variables based on their type (i.e., integer, floating point, string). Apple Basic had the same concept -- that the suffix determined the type of variable. It could very well be that identifiers NH and NH(1) represented different things.

Very long time ago, indeed -- going on 40 years.
 
  • #12
Please post the code block (at least the 10 previous lines). It doesn't have to be everything, but we need context.
If there are relevant variable declarations (which might be way up at the top), it woud be good to include those too.
 
  • #13
Mark44 said:
I was thinking the same thing but didn't weigh in.
Me too. I wish I were at home because I still have a working TRS80 and a RS model 100 laptop. Well, they were working the last time I fired them up about 10 years ago :)
 
  • #14
DaveC426913 said:
Please post the code block (at least the 10 previous lines). It doesn't have to be everything, but we need context.
If there are relevant variable declarations (which might be way up at the top), it woud be good to include those too.
I want to thank everyone for their input.

This is the start of the program. I think the Dim statements are the only declarations.
Code:
10   B$ = Chr$(7)
     Dim CL(20), CW(20), ES(20), FR(20), LS(20), RS(20), SP(20), XX(20), Z1(20), Z2(20), Z3(20), Z5(20), Z6(20), Z7(20)
     Dim CM(20), CN(20), ML(20), P(20), S(20), K(20), L(20), MS(20), CF(20)
40   For I = 1 To 25: Print: Next I

These lines lead up to the first error.
Code:
840  INPUT "SURFACE "; A$
     If A$ = "" Then Print B$: GoTo 840
     If A$ = "999" Then GoTo 790
     If A$ <> "T" And A$ <> "D" Then Print B$: GoTo 840
     ST$ = A$
890  INPUT "FIRST TIME (SECONDS,FIFTHS) "; S, FS
     If S = 999 Or FS = 999 Then GoTo 840
     GoSub 3630
     If FU$ <> "" Then GoTo 890
     FF = S + 0.2 * FS
 
  • #15
Dim statements are only declarations, indeed.

To get rid of the error, change S to S1 or something else different from S in these two lines:
890 INPUT "FIRST TIME (SECONDS,FIFTHS) "; S, FS
If S = 999 Or FS = 999

and see where things go awry next (S is very likely used further on as some initial time or so)
 
  • #16
Well, there is no NH in that block of code, so your opening post isn't helpful.

One thing you are going to have to learn is how to describe a bug concisely. You've got us chasing geese.

Describe the exact error, word for word.
Show the exact line that is causing the error (or at least where the program terminated).
Show as much code as is necessary to provide context. (which you have now done)As BvU points out, it does seem that S is both a primitive and an array.
It is declared as S(20) in line 30, yet it is used as an input S (which will surely be a string) in lines 890 and then 930.
 
  • #17
DaveC426913 said:
As BvU points out, it does seem that S is both a primitive and an array.
It is declared as S(20) in line 30, yet it is used as an input S (which will surely be a string) in lines 890 and then 930.
In line 890, S is used as a numeric variable (to hold the number of seconds), not a string.
 
Last edited:
  • #18
BvU said:
Dim statements are only declarations, indeed.

To get rid of the error, change S to S1 or something else different from S in these two lines:
890 INPUT "FIRST TIME (SECONDS,FIFTHS) "; S, FS
If S = 999 Or FS = 999

and see where things go awry next (S is very likely used further on as some initial time or so)
That works. Thanks all.
 
  • #19
If further on S and FS aren't used anymore, only FF then you might be OK.
Prophet said:
That works.
Centuries old fallacy: it compiles, it runs, so it's correct. Stay alert !
 
  • #20
BvU said:
If further on S and FS aren't used anymore, only FF then you might be OK.

The well known Sod's Law applies in this situation .

Citation
 
Last edited by a moderator:
  • Like
Likes BvU
  • #21
DaveC426913 said:
You've got us chasing geese.
Wild Geese.
A BASIC program was written late last century by a student who never managed to make it work. We do not have a full copy of the source. We do not know what it was supposed to do. Please post the full source if it is not confidential.

In some early BASICs, NH referred to the zeroth element of array NH, NH(0).
I remember when arrays of up to 10 elements did not need to be dimensionned.
 

1. What is a "Basic program -- missing array index"?

A "Basic program -- missing array index" refers to an error that occurs in a computer program written in the BASIC programming language. This error happens when an array index, which is used to access a specific element in an array, is not specified or is out of bounds.

2. How does a missing array index affect a program?

A missing array index can cause a program to crash or produce incorrect results. This is because the program is unable to access the intended element in the array, leading to unexpected behavior.

3. What causes a missing array index?

A missing array index is usually caused by a mistake in the program's code, such as forgetting to specify the index or using an incorrect index value. It can also occur if the program is expecting a certain index to exist, but it is not present in the array.

4. How can a missing array index be fixed?

To fix a missing array index, the program's code needs to be carefully reviewed to identify where the error is occurring. Once the error is found, the programmer can add the missing index or correct the existing index to ensure the program can access the correct element in the array.

5. How can a missing array index be prevented?

To prevent a missing array index, it is important to carefully plan and test the program's code before running it. This includes making sure all array indexes are correctly specified and within the bounds of the array. Proper error handling techniques can also help prevent a missing array index from causing a program to crash.

Similar threads

  • Programming and Computer Science
Replies
20
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
5
Views
5K
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
4
Views
7K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • General Math
Replies
16
Views
2K
Back
Top