Bad File Mode 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

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

Bad File Mode Error

Post by JasonQuinn1992 » Sun Nov 25, 2012 12:46 pm

I get a bad file mode error on the WRITE #1, SalesNum, SalesmanNam$, SalesAmt, CommRt, CommissionAm line


what should I do?

My Code

' This program reads a sequential file
'
'
'
'
' SalesNum = Salesman Number
' SalesmanNam$ = Salesman Name
' SalesAmt = Sales Amount
' CommRt = Commission Rate
' CommissionAm = Commission Amount
'
' *******************************************
' Program mainline
' *******************************************
CLS
GOSUB CreateFile
GOSUB LoadFile
GOSUB CloseFile
END

' ******************* Create The File ***************

CreateFile:
OPEN "SALEDATA" FOR INPUT AS #1
RETURN

' ************ Print The Report ***************

PrintReport:
INPUT #1, SalesNum, Nam$, SaleAmt, CommRt
DO UNTIL SalesNum = 0
LET Comm = SaleAmt * (CommRt / 100)
PRINT USING D$; SalesNum; Nam$; SaleAmt; CommRt; Comm
INPUT #1, SalesNum, Nam$, SaleAmt, CommRt
LOOP
RETURN

LoadFile:
DO UNTIL UCASE$(SalesmanNam$) = "END"
INPUT "Salesman Number", SalesNum
INPUT "Salesman Name", SalesmanNam$
INPUT "Sales Amount", SalesAmt
INPUT "Commission Rate", CommRt
INPUT "Commission Amount", CommissionAm
PRINT
WRITE #1, SalesNum, SalesmanNam$, SalesAmt, CommRt, CommissionAm
LOOP
RETURN
'****************************************************************************
' Close File
'****************************************************************************

CloseFile:
CLOSE #1
RETURN

User avatar
burger2227
Veteran
Posts: 2435
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Sun Nov 25, 2012 9:10 pm

OUTPUT or APPEND with WRITE
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 » Sun Nov 25, 2012 10:23 pm

LoadFile:
DO UNTIL UCASE$(SalesmanNam$) = "END"
INPUT "Salesman Number", SalesNum
INPUT "Salesman Name", SalesmanNam$
INPUT "Sales Amount", SalesAmt
INPUT "Commission Rate", CommRt
INPUT "Commission Amount", CommissionAm
PRINT
LINE INPUT #1, SalesNum, SalesmanNam$, SalesAmt, CommRt, CommissionAm
LOOP
RETURN

I fixed that but now I get an expected: variable or end-of-statement on the SalesmanNam$ variable. How should I fix this I already tried adding semi-colons

User avatar
burger2227
Veteran
Posts: 2435
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Mon Nov 26, 2012 5:28 pm

LINE INPUT expects ONE string variable. Commas can only separate a variable list in an INPUT statement.
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 » Mon Nov 26, 2012 6:05 pm

I believe i fixed that error as I try to print the data on the screen, the screen just prints blank or black, im not sure if im missing data because here is my .txt file data

COMMISSION AMOUNT BY SALESMAN

Salesman Number Salesman Name Sales Amount Commission Rate

1245, HERMAN HOLLERITH, 1157.85, 6.5
1386, BLAISE PASCAL, 2540.00, 5
1457, CHARLES BABBAGE, 1853.70, 4
1819, JOHN ATANASOFF, 650.00, 4
1722, JOHN VON NEUMANN, 1000.00, 5
"END", 0,0,0,0

' This program reads a sequential file
'
'
'
'
' SalesNum = Salesman Number
' SalesmanNam$ = Salesman Name
' SalesAmt = Sales Amount
' CommRt = Commission Rate
' CommissionAm = Commission Amount
'
' *******************************************
' Program mainline
' *******************************************
CLS
GOSUB OpenFile
GOSUB PrintReport
GOSUB CloseFile
END

OpenFile:
OPEN "SALEDATA.txt" FOR INPUT AS #1
RETURN

PrintReport:
INPUT #1, SalesNum, Nam$, SaleAmt, CommRt
DO UNTIL SalesNum = 0
LET CommissionAm = SaleAmt * (CommRt / 100)
PRINT USING D$; SalesNum; Nam$; SaleAmt; CommRt; Comm
INPUT #1, SalesNum, Nam$, SaleAmt, CommRt
LOOP

RETURN

'****************************************************************************
' Close File
'****************************************************************************

CloseFile:
CLOSE #1
RETURN


Can you please look at my input file and see if you can find why the data is not printing?

Post Reply