You are here:

Qbasic, Quickbasic/Sequential File wont print data

Advertisement


Question
I have to create an sequential file that will read and print a .DAT file on the screen

here is the data that needs to be read:

         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


Here is my input file that contains an equation to calculate the commission amount (LET CommissionAm = SaleAmt * (CommRt / 100) However when attempting to run this program I get an Illegal Fuction Call error on the

PRINT USING D$; SalesNum; Nam$; SaleAmt; CommRt; Comm line. When I did get it to print the screen was just blank

Here is my output file

' 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.dat" 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

here is my output file

REM*****THIS PROGRAM IS DESIGNED TO CERATE A SEQUENTIAL DATA FILE******

REM*******************PROGRAM VARIABLES****************
REM SPERSONNUM$          SALES PERSON'S NUMBER
REM NAM$          NAME
REM CommRt$          COMMISSION RATE
REM SaleAmt$          AMOUNT OFSALARIES
REM CommissionAm    Commission Amount

REM *******************MAIN MODULE*********************

GOSUB OpenFile
GOSUB CreateFile
GOSUB CloseFile
PRINT
PRINT " END OF PROGRAM "
END

REM ********************OPEN FILE***********************
OpenFile:
      OPEN "SALEDATA.DAT" FOR OUTPUT AS #1
RETURN
REM *******************CREATE FILE**********************
CreateFile:
 GOSUB InputSalesmanNum
 DO UNTIL SPERSONNUM = 0
         GOSUB InputSalesData
         GOSUB WriteRecord
         GOSUB InputSalesmanNum
     LOOP
 RETURN
REM *********INPUT SALESMAN NUMBER*********************
InputSalesmanNum:
   CLS
   LOCATE 9, 14
   PRINT "ENTER SALESMAN NUMBER";
   INPUT "(ENTER 0 TO END)", SPERSONNUM
 RETURN
REM *************SALES DATA******************************
InputSalesData:
 LOCATE 11, 14
 INPUT " SALESMAN NAME          ", NAM$
 LOCATE 13, 14
 INPUT "ENTER SALE AMOUNT          ", SaleAmt
 LOCATE 15, 14
 INPUT "ENTER COMMISSION RATE          ", CommRt
RETURN

REM *****************WRITE RECORD TO DISK****************
WriteRecord:
    WRITE #1, SPERSONNUM, NAM$, SALAMT, CommRt
RETURN
REM *****************CLOSE FILE***********************
CloseFile:
   CLOSE #1
RETURN

So my question is how do i get this program to print the data on the screen?

Answer
Hi Dan,

I seem to be answering many of the classmates' questions, too.  You should really tell your teacher that (s)he's doing something wrong with the high volume of QBasic questions I'm receiving from his/her class.

You seem to be missing huge chunks of your code, such as setting D$ to something (and something PRINT USING can use).

One thing I told another one of the students from your class is that you need to break down all of the things you want your program to do, and think about how you can break them down into small tasks that you can code in QBasic.

Also remember that the computer is very dumb - you need to give it every piece of information you want it to use: there is no way for your program to magically figure out what you want it to do.

Figure out what D$ should be, and if you run into problems after that, you can do a followup question on here, but I will not do your homework for you.

Take care,
-Alex

Qbasic, Quickbasic

All Answers


Ask Experts

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

©2016 About.com. All rights reserved.