AboutAlex 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++
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.