linear data search error query

Here you can talk about anything related to BBC BASIC, not covered in another category
gerard@dugdill.com
Posts: 11
Joined: Wed 25 Sep 2024, 13:35

linear data search error query

Post by gerard@dugdill.com »

So I load this into the BASIC programme and hit Run but just get an error message, "No such variable". Is that supposed to happen? I am trying to test a very basic linear search program for the decision maths course. This one seemed to fit the bill.... kr

DATA FRED,17,BILL,21,ALLISON,21,NOEL,32
DATA JOAN,26,JOHN,19,WENDY,35,ZZZZ,0
REPEAT
READ list$,age
IF list$=name$ THEN PRINT name$,age
UNTIL list$=name$ OR list$="ZZZZ"
IF list$="ZZZZ" PRINT "Name not in list"
Richard Russell
Posts: 366
Joined: Tue 18 Jun 2024, 09:32

Re: linear data search error query

Post by Richard Russell »

gerard@dugdill.com wrote: Tue 06 May 2025, 10:15 So I load this into the BASIC programme and hit Run but just get an error message, "No such variable". Is that supposed to happen?
As far as I can see it's complaining that the variable name$ in this line doesn't exist:

Code: Select all

        IF list$=name$ THEN PRINT name$,age
So to that extent it's "supposed to happen", yes. Is there perhaps some code missing which should be initialising name$?
gerard@dugdill.com
Posts: 11
Joined: Wed 25 Sep 2024, 13:35

Re: linear data search error query

Post by gerard@dugdill.com »

I am not sure. I seemed to find the exact program I was looking for when looking through the DATA entry in the keyword section of the help guide manual, excerpt below.


DATA...

The following example program segment reads through a list of names looking for the name in 'name$'. If the name is found, the name and age are printed. If not, an error message is printed.

DATA FRED,17,BILL,21,ALLISON,21,NOEL,32
DATA JOAN,26,JOHN,19,WENDY,35,ZZZZ,0
REPEAT
READ list$,age
IF list$=name$ THEN PRINT name$,age
UNTIL list$=name$ OR list$="ZZZZ"
IF list$="ZZZZ" PRINT "Name not in list"
Richard Russell
Posts: 366
Joined: Tue 18 Jun 2024, 09:32

Re: linear data search error query

Post by Richard Russell »

gerard@dugdill.com wrote: Wed 07 May 2025, 17:47 I seemed to find the exact program I was looking for when looking through the DATA entry in the keyword section of the help guide manual, excerpt below.
Yes, but as it says that's only a program segment to illustrate one use of DATA, not a self-contained program. Like most code examples in the manual, it's not useful on its own but only as part of a larger program. What are you trying to do?
gerard@dugdill.com
Posts: 11
Joined: Wed 25 Sep 2024, 13:35

Re: linear data search error query

Post by gerard@dugdill.com »

Run the whole program to search for a particular data item using linear search (and then binary search).

Often hit the no such variable barrier.

)
Richard Russell
Posts: 366
Joined: Tue 18 Jun 2024, 09:32

Re: linear data search error query

Post by Richard Russell »

gerard@dugdill.com wrote: Thu 08 May 2025, 12:13 Run the whole program to search for a particular data item using linear search (and then binary search).
The binary-chop method is described, in flow-chart form, here. I use it quite commonly myself.
gerard@dugdill.com
Posts: 11
Joined: Wed 25 Sep 2024, 13:35

Re: linear data search error query

Post by gerard@dugdill.com »

Thanks,