A Basic program -- missing array index?

  • Thread starter Prophet
  • Start date
  • #1
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.
 

Answers and Replies

  • #2
BvU
Science Advisor
Homework Helper
2019 Award
13,531
3,250
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
1,516
617
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
12,020
5,671
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
1,367
61
Understanding other's programs is not an easy task. If the program is small, I would write it from scratch.
 
  • #6
18
0
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
Science Advisor
Homework Helper
2019 Award
13,531
3,250
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
Merlin3189
Homework Helper
Gold Member
1,597
733
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
18
0
Hello Mr Prophet (or is it a first name ?)
It's a surname. It's Scottish believe it or not.
 
  • #10
BvU
Science Advisor
Homework Helper
2019 Award
13,531
3,250
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
33,960
5,615
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
DaveC426913
Gold Member
18,901
2,409
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
887
98
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
18
0
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
BvU
Science Advisor
Homework Helper
2019 Award
13,531
3,250
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
DaveC426913
Gold Member
18,901
2,409
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
33,960
5,615
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
18
0
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
BvU
Science Advisor
Homework Helper
2019 Award
13,531
3,250
If further on S and FS aren't used anymore, only FF then you might be OK.
That works.
Centuries old fallacy: it compiles, it runs, so it's correct. Stay alert !
 
  • #20
Nidum
Science Advisor
Gold Member
2,990
848
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
Baluncore
Science Advisor
2019 Award
7,971
2,854
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.
 

Related Threads on A Basic program -- missing array index?

  • Last Post
Replies
1
Views
597
Replies
3
Views
9K
  • Last Post
Replies
16
Views
3K
  • Last Post
Replies
13
Views
3K
Replies
13
Views
3K
Replies
13
Views
1K
Replies
21
Views
1K
Replies
1
Views
2K
Replies
31
Views
3K
Top