A Basic program -- missing array index?

AI Thread Summary
The discussion centers around troubleshooting a BASIC program that contains problematic code, specifically referencing lines where array variables are not properly indexed, leading to compiler errors. The original poster is seeking help due to the lack of responses on other forums. Key issues identified include the use of the variable "NH" without an index, which may stem from the original programmer's potential reliance on a compiler feature or an incomplete implementation. Participants suggest that the program might have been left unfinished, possibly by a student. They discuss the implications of variable naming conventions in BASIC, such as the distinction between scalar and array variables, and the potential confusion arising from the reuse of variable names like "S." Recommendations include changing variable names to avoid conflicts and providing more context by sharing additional lines of code. The conversation emphasizes the importance of clarity in describing bugs and the challenges of understanding legacy code.
Prophet
Messages
18
Reaction score
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
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 ?
 
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.
 
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.
 
Understanding other's programs is not an easy task. If the program is small, I would write it from scratch.
 
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
                     ^
 
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...
 
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:
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.
 
Back
Top