You are here:

# Qbasic, Quickbasic/Expected: variable or end-of-statement error ?

Question
QUESTION: Hello, Im a college student that is taking a BASIC/QBASIC programming class as part of a Web pg design major.. As part of the final in that class I have to Compute and output the amounts earned by each of these salespeople:

Salesperson         Gross Sales
Carlos Ortiz         \$90,000
Jill Johnson         \$70,000
Don Williams         \$20,000
Dee Jones         \$95,000
Al Ennis         \$40,000
My code is below, but i keep getting an Expected: variable or end-of-statement error on the the LINE INPUT #x, person, grosssale, when I switched the "Line Input" to Input I got an "Input past end of file" error

so how should I got about fixing the xpected: variable or end-of-statement error on the the LINE INPUT #x, person, grosssale ? Because ive gotten it on our files as well
My code is below:

DIM x AS INTEGER
DIM person AS STRING, grosssale AS DOUBLE
DIM salary AS DOUBLE

x = FREEFILE

OPEN "sales.dat" FOR INPUT AS #x
WHILE NOT EOF(x)
LINE INPUT #x, person, grosssale
salary = 10000 + .1 * grosssale
IF grosssale > 80000 THEN
salary = salary + 500
END IF
PRINT person; " : "; salary
WEND
CLOSE #1

After looking over your code, I think the issue is probably how the data is saved in the file.  Can you show me what sales.dat looks like?

Also, you'll definitely want to use INPUT rather than LINE INPUT - LINE INPUT literally takes a whole line from a file and tosses it into the first variable, than repeats, so if your file looks like:

Carlos, \$90,000
Jill, \$70,000
Don, \$20,000

LINE INPUT would get the following for you:

LINE INPUT person\$, amount#
PRINT person\$
PRINT amount#
'' Output:
'' Carlos, \$90,000
'' 70

The reason the second is 70 is because it tries to convert the string into a DOUBLE, but QBasic doesn't know what to do with your dollar sign or comma, so it takes the first number amount it "sees", which is 70.

So, before I see your file, this is how it should probably look:

```"Carlos Ortiz", 90000
"Jill Johnson", 70000
"Don Williams", 20000
"Dee Jones", 95000
"Al Ennis", 40000```

By using quotes, QBasic's INPUT can determine when a string begins and ends, and the comma is used to tell QBasic we're dealing with separate variables.

```DIM x AS INTEGER
DIM person AS STRING, grosssale AS DOUBLE
DIM salary AS DOUBLE

x = FREEFILE

OPEN "sales.dat" FOR INPUT AS #x

WHILE NOT EOF(x)
INPUT #x, person, grosssale
salary = 10000 + .1 * grosssale
IF grosssale > 80000 THEN
salary = salary + 500
END IF
PRINT person; " : "; salary
WEND

CLOSE #1```

I hope that helps,
-Alex

---------- FOLLOW-UP ----------

QUESTION: here is what the "sales.dat" file looks like

Salesperson          Gross Sales
DATA Carlos Ortiz,          90000
DATA Jill Johnson,          70000
DATA Don Williams,          20000
DATA Dee Jones,          95000
DATA Al Ennis,          40000
DATA, 0,0

So when you're reading from a file, QBasic doesn't actually run commands like DATA

DATA is used for in-program information (rather than a file source) - if the project you're working on requires you to use in-program information, then add this to the bottom of your BAS file:

```DATA "Carlos Ortiz", 90000
DATA "Jill Johnson", 70000
DATA "Don Williams", 20000
DATA "Dee Jones", 95000
DATA "Al Ennis", 40000
DATA "", 0```

Using DATA would mean you'd have to restructure your program to do the appropriate READ rather than INPUT, and you wouldn't need to use a file/file handle.

If you are supposed to use a file, sales.dat should look like this:

```"Carlos Ortiz", 90000
"Jill Johnson", 70000
"Don Williams", 20000
"Dee Jones", 95000
"Al Ennis", 40000```

Try putting that into your sales.dat and see what happens - if it doesn't work, I can re-look at your code and file.

Take care,
-Alex

Qbasic, Quickbasic

Volunteer

#### Alex Barry

##### Expertise

I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, QB64, c/c++, python, lua, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.

##### Experience

I have been programming in *Basic dialects since 2000, as mentioned in my expertise. After a year of QBasic, I learned C and C++, and dabbled a little in ASM (I don't program in ASM - I literally just played around to see how things work). When QB64 and FreeBASIC were released, I played with those languages. At the time, FreeBASIC offered more functionality and I sided with that language for a while. During that time, while I was learning new languages, that I would see what scripting languages are available, where I took up python and lua. I started to notice a staleness to QB64's development (which I kept tabs on from time to time), and am now trying to be active in it's community and maybe in it's development in the future. Currently, I am only active on the QB64.net forums, but I appear on occasion on FreeBASIC.net's forums as well.

Education/Credentials
Highschool - 2007