Syntax Error

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

JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Syntax Error

Post by JasonQuinn1992 »

Why am I getting a syntax error on this line:

" READ man$, Yr, Make, Model, Desc, Price"

My code:


' Program that lists inventory for your collection of model cars
'
'
'
' Variables Used

' T1$, H1$, H2$, D1$ Print images
' TL$ Print images
' man$ Manufacturer #
' Yr Year Of Csr
' Make Make of Car
' Model Model Of Car
' Desc Description of car
' Price Price Of Car

' Program Mainline

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB PrintTotals
END

' Initalize Variables

InitializeVariables:
LET T1$ = ""
LET H1$ = ""
LET H2$ = " Manufacturer # Yr Make Description Price"
LET D1$ = "\ \ ## \ \ \ \ $ ###.##"
LET TL$ = " TOTAL $ ###.##"
RETURN

'
' Initialize Imagees

InitializeImages:

' T1$ Title Line
' H1$, H2$ Column Headings
' D1$ Deatail (manufacturer #, Yr, Make, description, price)
' TL$ Totals

' LPRINT HEADINGS

PrintHeadings:
PRINT T1$; 'Print title line
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
RETURN

' Process Detail

ProcessDetail:
GOSUB ReadData
DO UNTIL UCASE$(man$) = "END"
GOSUB PrintDetail
GOSUB ReadData
LOOP
RETURN

' Read Input Data

ReadData:
READ man$, Yr, Make, Model, Desc, Price
DATA BMR-R79, 49, FIAT, 500B, GILLETE RAZOR, $7.99
DATA HOTWELS-34, 57, CHEVY, NOMAD, 4/DR STATION WAGON, $12.95
DATA MATCHBX-878, 73, FORD, BRONC, 3/DR 4X4 RED SPARE WHL, $25.99
DATA MATCHBX-72, 69, BUIK, CENTY, YELLOW TAXI, $1.49
DATA BRM-R88, 34, BUGANT, TY575, RACER, BLACK $35.00
DATA MATCHBX-25, 80, LINCO, MRKIV, WHITE, LIMOUSINE, $14.99
DATA LESNEY-Y42, 82, CHEVY, MALBU, 4/DR GREEN PASSENGER, $1.99
DATA HASBRO-119, 75, AMC, GRMLN, 2/DR SENAN, YELLOW, $1.69
DATA TABY-6332, 71, TOYOT, CELIC, 2/DR SEDAN, BLUE, $2.99
DATA BMR-SY238, 36, ROLRY, SYLVC, 4/DR SEDAN, SILVER-GRAY, $60.00
RETURN

' Print Detail

PrintDetail:
LPRINT USING H2$; man$; Yr; Make; Model; Desc; Price
RETURN

' Print Totals

PrintTotals:
PRINT
PRINT USING TL$; Price
RETURN
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Take the DATA out of the GOSUB routine. Use a loop to read more than one line of data. Use RESTORE to start reading from the start again if needed.

DATA cannot be inside of the procedure.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

OK so I should have it like this?

' Process Detail

ProcessDetail:
DO UNTIL UCASE$(man$) = "END"
GOSUB PrintDetail
GOSUB PrintTotals
LOOP
RETURN

' Read Input Data

GOSUB ReadData
PRINT man$, Yr, Make, Model, Desc, Price
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can put GOSUB ReadData in the loop too, but you will have to add and END line of DATA or count the times data is read:

DATA "END" , 0, " ", " ", " ", " ", " "
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

Now I get a Tpe Mismatch error error on this line:


PRINT USING H2$; man$; Yr; Make$; Model$; Desc$; Price$
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

According to your READ statement they are not strings:

READ man$, Yr, Make, Model, Desc, Price


PRINT USING H2$; man$; Yr; Make$; Model$; Desc$; Price$

The types must match! QB thinks Model is a number while Model$ is a string value.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

I did that because i thought i would fix the syntax error but it didnt..... the type mismatch is resolved but now the syntax error is back on the READ man$, Yr, Make$, Model$, Desc$, Price line here is how I have my process code and read data:

ProcessDetail:
GOSUB ReadData
DO UNTIL UCASE$(man$) = "END"
GOSUB PrintDetail
LOOP
RETURN

' Read Input Data

PRINT man$, Yr, Make$, Model$, Desc$, Price

ReadData:
READ man$, Yr, Make$, Model$, Desc$, Price
DATA BMR-R79, 49, FIAT, 500B, GILLETE RAZOR, $7.99
DATA HOTWELS-34, 57, CHEVY, NOMAD, 4/DR STATION WAGON, $12.95
DATA MATCHBX-878, 73, FORD, BRONC, 3/DR 4X4 RED SPARE WHL, $25.99
DATA MATCHBX-72, 69, BUIK, CENTY, YELLOW TAXI, $1.49
DATA BRM-R88, 34, BUGANT, TY575, RACER, BLACK $35.00
DATA MATCHBX-25, 80, LINCO, MRKIV, WHITE, LIMOUSINE, $14.99
DATA LESNEY-Y42, 82, CHEVY, MALBU, 4/DR GREEN PASSENGER, $1.99
DATA HASBRO-119, 75, AMC, GRMLN, 2/DR SENAN, YELLOW, $1.69
DATA TABY-6332, 71, TOYOT, CELIC, 2/DR SEDAN, BLUE, $2.99
DATA BMR-SY238, 36, ROLRY, SYLVC, 4/DR SEDAN, SILVER-GRAY, $60.00
DATA END,0,0,0,0,0
RETURN


i need to be able to calculate the total price by equaling the sum of all prices... so maybe I have something wrong in the process code?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can't put the DATA inside the GOSUB routine. DATA can be placed anywhere else. You can label it and use RESTORE MyData to read it again.

Commas in DATA separates values. You can only have 6 values per row to match up the data with your variables.

Code: Select all

CLS

H2$ = "Vehicle & Yr: ## Make: &  & Desc: & Price $&"

'RESTORE MyData
DO
  GOSUB ReadData
  IF man$ = "END" THEN EXIT DO
  GOSUB PrintDetail
  'SLEEP
LOOP

END


ReadData:
READ man$, Yr, Make$, Model$, Desc$, Price$
RETURN

PrintDetail:
PRINT USING H2$; man$; Yr; Make$; Model$; Desc$; Price$
RETURN

MyData:
DATA BMR-R79,49,FIAT,500B,GILLETE RAZOR,7.99
DATA HOTWELS-34,57,CHEVY,NOMAD,4/DR STATION WAGON,12.95
DATA MATCHBX-878,73,FORD,BRONC,3/DR 4X4 RED SPARE WHL,25.99
DATA MATCHBX-72,69,BUIK,CENTY,YELLOW TAXI,1.49
DATA BRM-R88,34,BUGANT,TY575,RACER BLACK ,35.00
DATA MATCHBX-25,80,LINCO,MRKIV,WHITE LIMOUSINE,14.99
DATA LESNEY-Y42,82,CHEVY,MALBU,4/DR GREEN PASSENGER,1.99
DATA HASBRO-119,75,AMC,GRMLN,2/DR SEDAN YELLOW,1.69
DATA TABY-6332,71,TOYOT,CELIC,2/DR SEDAN BLUE,2.99
DATA BMR-SY238,36,ROLRY,SYLVC,4/DR SEDAN BLACK,60.00
DATA "END",0,0,0,0,0,0

PRINT USING needs symbols to place string values.

& will place any length string, but may run too wide for the screen

\ \ will limit a string to a fixed length set by the spaces from one to the other including slashes.

## will give you the 2 numerical digits

http://qb64.net/wiki/index.php?title=PRINT_USING
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

somehow Im getting a type mismatch error on

PRINT USING H2$; man$; Yr; Make$; Model$; Desc$; Price


I get that everything has to match and it is
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Change Price to Price$. It has to be a string or you will need ###.##. in the template. Also you cannot use $ with the DATA number value, only a string value. In the template you can put the $ before a string or put $$###.## for just the decimal point number. $ does not need to be in the DATA.

Template symbol $$ places a $ immediately before the highest non-zero digit with numbers only. That way you can use more # digits than you need
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

I changed everything as you said and as I was told by my instructor but i keep getting error, either the syntax or type mismatch.... this time its type mismatch on this line....

READ man$, Yr, Make$, Model$, Desc$, Price$

and when i tried changing it to look like the "PRINT" line I got an "expected , or end-of-statement" error

ReadData:
READ man$, Yr, Make$, Model$, Desc$, Price$
RETURN
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can read and print everything as strings. Try that!

If you get an Out of Data error, check that each DATA line has 6 values.

Did you try my code? It works.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

I retried your code and it worked! Now however I m not sure where to put my GOSUB to calculate the total price for all the cars within the Process Data?

And is there anyway to put the data into column form so they lineup with my headings?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can put that loop back into your GOSUB routine. I copied it from that. Just move END above all of your GOSUB procedures and after the calls in the main program area END prevents a RETURN without GOSUB error.


Line up the header print and the template:

Code: Select all

  PRINT "Vehicle    Year     Make     Model     Description                     Price"
temp$ = "&           &       &        &         &                                $&"
Since your string values are longer some places, this may not be easy to do. It is trial and error so use PRINT USING to see what it look like on the screen before using LPRINT and wasting ink and paper.

You could use PRINT #1, USING to print the text to a file and use Notepad to print it on the printer later. Thet would just require using a SHELL command to Notepad.
Last edited by burger2227 on Tue Oct 16, 2012 5:38 pm, edited 1 time in total.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

that seems to work a little bit.... under my Print Detail couldnt I replace the H2$ with my my detail line, D1$ to print the data is straight columns...?? I ask because when I ran the program all my column headings where already printed I was just adding another header line

can i post a pic of what i need it to look like?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can post a link to a picture or upload a picture to Drop Box. I see you are already a member.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

https://www.dropbox.com/s/c12o7q3r3s2y0i6/ch5.jpg

this is what i need the output screen to look like..... as i said I already have the headings set.. I need a total line that gives me the sum of the "Price column

I tried switching the PRINT Detail to print using d1$, since that what i need to print and i keep getting an error

PrintDetail:
PRINT USING D1$; man$; Yr; Make$; Model$; Desc$; Price$ 'Print details
RETURN

Any idea why?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

It needs 6 variable symbol places in the template:

D1$ = "\ \ ## \ \ \ \ $ ###.##" 'only has 5


Since none of the text is missing use & for the string values:

D1$ = "& ## & & & $$###.##"

Double $$ so dollar sign stays at start of price value.

Trial and error until it looks close. I see you are using the numerical values instead of string. Whatever works.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

Okay I believe I was able to get the Type Mismatch error to disappear.. I emailed a fellow student in my class andthey emailed to me how their process detail was set up so I fix it as shown below;


'Process Detail

ProcessDetail:
GOSUB ReadData
DO UNTIL Manufact$ = "END"
GOSUB CalculateTotal
GOSUB PrintDetail
GOSUB ReadData
LOOP

END

ReadData:
READ Manufact$, Yr, Make$, Model$, Desc$, Price
RETURN

PrintDetail:
PRINT USING D1$; "Manufact$; Yr; Make$; Model$; Desc$; Price"
RETURN

READ Manufact$, Yr, Make$, Model$, Desc$, Price
DATA BMR-R79, 49, FIAT, 500B, GILLETE RAZOR, $7.99
DATA HOTWELS-34, 57, CHEVY, NOMAD, 4/DR STATION WAGON, $12.95
DATA MATCHBX-878, 73, FORD, BRONC, 3/DR 4X4 RED SPARE WHL, $25.99
DATA MATCHBX-72, 69, BUIK, CENTY, YELLOW TAXI, $1.49
DATA BRM-R88, 34, BUGANT, TY575, RACER, BLACK $35.00
DATA MATCHBX-25, 80, LINCO, MRKIV, WHITE, LIMOUSINE, $14.99
DATA LESNEY-Y42, 82, CHEVY, MALBU, 4/DR GREEN PASSENGER, $1.99
DATA HASBRO-119, 75, AMC, GRMLN, 2/DR SENAN, YELLOW, $1.69
DATA TABY-6332, 71, TOYOT, CELIC, 2/DR SEDAN, BLUE, $2.99
DATA BMR-SY238, 36, ROLRY, SYLVC, 4/DR SEDAN, SILVER-GRAY, $60.00
DATA "END",0,0,0,0,0,0
RETURN






however I still get that pesky syntax error on the
READ Manufact$, Yr, Make$, Model$, Desc$, Price$ line
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Go back and READ what I told you before! You keep doing the same mistakes over and over!

No dollar signs in DATA when using a number.

Where is the template? You quoted the PRINT USING variables. That makes a string value
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply