Syntax Error #2

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
flirt85
Coder
Posts: 13
Joined: Sun Mar 12, 2006 2:14 pm

Syntax Error #2

Post by flirt85 »

Hi again. I can't seem to figure out READ statments. In the following
code (about the middle), I get a syntax error on the line "READ city, pop". Any ideas are appreciated!


COLOR 15, 1
CLS
DIM pass AS STRING 'password
DIM ct AS INTEGER 'counter

INPUT "Password: ", pass 'enter password
WHILE UCASE$(pass) <> "GO"
ct = ct + 1
REM aborts programs after 3 tries
IF ct = 3 THEN LOCATE 8, 38: PRINT "GoodBye": END
INPUT "Not a valid password, Re-enter: ", pass
WEND

LOCATE 8, 35
PRINT "Password Accepted"
SLEEP 3

DIM city AS STRING 'city
DIM pop AS LONG 'population
DIM x AS INTEGER 'For loop variable
DIM cityin AS STRING 'selected city
DIM yn AS STRING 'continue y or n choice
DIM pstring AS STRING 'print format string

DATA "Cottonwood",5918"
DATA "Flagstaff",45857
DATA "Camp Verde",6243
DATA "Sedona",7720
DATA "Prescott",26455
DATA "Jerome",403
DATA "xxx",-1

CLS
ct = 0 'reset ct to 0
READ city, pop This is the line where I get the error
WHILE city <> "xxx" 'loops until trailer data
ct = ct + 1
PRINT city
READ city, pop
WEND
pstring = " \ \ Population #####, "
yn = "Y" 'sets yn yo "Y" to enter loop
WHILE UCASE$(yn) = "Y" 'loops while choice (y/n) is Y
LOCATE 8, 3 'locates output at input line
PRINT STRING$(50, " ") 'covers previous output with spaces
LOCATE 8, 3
INPUT "Type City name to see Population ", cityin
LOCATE 10
PRINT STRING$(50, " ") 'covers previous output with spaces
PRINT
RESTORE 'return pointer to beginning of data
COLOR 4, 2
PRINT STRING$(40, " ") 'prints spaces to color output area
FOR x = 1 TO ct 'use a FOR loop with the counter
READ city, pop 'prints with pstring format string
IF city = cityin THEN PRINT USING pstring; city; pop
NEXT x

PRINT STRING$(40, " ") 'prints spaces to cover output area
COLOR 15, 1 'returns color to beginning color
LOCATE 16, 13 'locates at y/n input space
PRINT " " 'covers previous input with space
LOCATE 16

PRINT "Do Another? (Press y or n)"
yn = ""
WHILE yn = ""
yn = INKEY$
WEND
WEND
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Post by Zim »

DATA "Cottonwood",5918"
DATA "Flagstaff",45857
DATA "Camp Verde",6243
DATA "Sedona",7720
DATA "Prescott",26455
DATA "Jerome",403
DATA "xxx",-1
That quote mark at the end of the first DATA statement line is gonna REALLY goof you up! Could that be it? I know a problem with DATA will show up as an error in the READ.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
flirt85
Coder
Posts: 13
Joined: Sun Mar 12, 2006 2:14 pm

Post by flirt85 »

Thank you! That solved everything.
User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Post by Seb McClouth »

B.t.w. I suggest you use sumfin else for the password thing. If you want I can you show. It somewhat resembles the visual basic password thingy.

grtz
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
Post Reply