# A Basic program -- missing array index?

1. Feb 16, 2017

### Prophet

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.

2. Feb 16, 2017

### BvU

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. Feb 16, 2017

### newjerseyrunner

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. Feb 16, 2017

### Staff: Mentor

That is very possible. Some student wrote it part way got a new job or started a new semester and left it unfinished.

5. Feb 16, 2017

### S_David

Understanding other's programs is not an easy task. If the program is small, I would write it from scratch.

6. Feb 17, 2017

### Prophet

Code ( (Unknown Language)):

posex.bas(97) error 72: Array access, index expected, before '='
If S = 999 Or FS = 999 Then GoTo 840
^

7. Feb 17, 2017

### BvU

I meant a bit more than one line...
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. Feb 17, 2017

### Merlin3189

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: Feb 17, 2017 9. Feb 17, 2017 ### Prophet It's a surname. It's Scottish believe it or not. 10. Feb 17, 2017 ### BvU Is this sitting inside a loop ? (If so then show the loop code ) 11. Feb 17, 2017 ### Mark44 ### Staff: Mentor 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. Feb 17, 2017 ### DaveC426913 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. Feb 17, 2017 ### TurtleMeister 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. Feb 18, 2017 ### Prophet 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 ( (Unknown Language)): 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 ( (Unknown Language)): 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. Feb 18, 2017

### BvU

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. Feb 18, 2017

### DaveC426913

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. Feb 18, 2017

### Staff: Mentor

In line 890, S is used as a numeric variable (to hold the number of seconds), not a string.

Last edited: Feb 19, 2017
18. Feb 18, 2017

### Prophet

That works. Thanks all.

19. Feb 19, 2017

### BvU

If further on S and FS aren't used anymore, only FF then you might be OK.
Centuries old fallacy: it compiles, it runs, so it's correct. Stay alert !

20. Feb 19, 2017

### Nidum

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

Citation

Last edited by a moderator: Jul 1, 2017