AllExperts > Experts 
Search      

Qbasic, Quickbasic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Qbasic, Quickbasic Answers
Question Library

Ask a question about Qbasic, Quickbasic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About 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, c/c++, python, 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
Hobby programming since 2000

I no longer belong to any community programming groups, but do have knowledge of *basic dialect and C/C++
 
   

You are here:  Experts > Computing/Technology > Basic > Qbasic, Quickbasic > qbasic

Topic: Qbasic, Quickbasic



Expert: Alex Barry
Date: 4/1/2008
Subject: qbasic

Question
Each month I save about 50 lines of equal length to a file Y08. When I print this random file with the statement:

open file for input as #1
DO WHILE NOT (EOF(1))
  INPUT #1, month$, job$, cost
  LPRINT month$
  Print using bill$; job$; cost
  monecost = monecost + cost

LOOP
What is happening is that the file prints only about 1/2 of the input.  Some months prints out all the input.
Any input into this problem will be much appreciated.
thanking you in advance
gerry racicot



Answer
Hi, Gerry,

I can't find an immediate problem with your code, so that tells me it's probably a problem with how you are saving it to a file.  Although I don't have all the information, this is what I suggest trying:

Type MoneyInfo
 month as string * 16
 job as string * 32
 cost as single
 ' add other fields if there is more information you want to store
End Type

declare sub AddToFile( file as integer, i as MoneyInfo )
declare sub ReadFile( file as integer, byref totalcost as single )

dim ff as integer
ff = FreeFile

open "yourfile.ext" for binary as #ff LEN=LEN(MoneyInfo)

' write to the file
dim mydata as MoneyInfo
mydata.month = "January"
mydata.job = "Construction"
mydata.cost = 60
AddToFile( ff, mydata )

' grab all data from the
dim total as single
ReadFile( ff, total )
print using "Total Cost: #####.##"; total

close #ff

end

sub AddToFile( file as integer, i as MoneyInfo )

 put #file,,i

end sub

sub ReadFile( file as integer, byref totalcost as single )

dim j as MoneyInfo
dim bill as string
' Set the string formatting here...
bill = ""

totalcost = 0.0

do until eof( file )

 get #file,,j
 print using bill; j.job, j.cost
 totalcost = totalcost + j.cost

loop

end sub

When you save various strings in a row in a file, it's best to use a fixed-length string - then you will never get more information in one variable than anywhere else.

Hope this helps you,
Alex

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.