Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
freefile to make appendable a random file?
#2
Hi guyisland,

the main reason is because when you just open the file you have no way, in the code you have there, to know where to append the record.

Here's a modified version of your code that will always append it where it should, at the end of the file.

Code:
CLS
TYPE namestype
     nm AS STRING * 10
     ln AS STRING * 10
     age AS INTEGER
END TYPE
DIM names AS namestype
DIM fh AS INTEGER
DIM recordcount AS INTEGER ' To get number of records in the file.

fh = FREEFILE
recordlen# = LEN(names)
OPEN "stubase.dat" FOR RANDOM AS #fh LEN = recordlen#

5

' here is were I evaluate the number of records.
RecordCount = LOF(fh) / Recordlen#
PRINT "There are currently " + STR$(RecordCount) + " records in the database."

INPUT "name: ", names.nm
INPUT "last name: ", names.ln
INPUT "age:", names.age
PUT #fh, RecordCount + 1 , names
INPUT "any more data?", more$
       IF more$ = "y" GOTO 5 ELSE
CLOSE #fh
END

LOF gives you the lenght of the file in bytes.  if you divide that length by the size of a record (recordlen# in this case) it gives you the number of physical record in the database.  Run it once, and you'll see that every time you run it, you have an extra record added in the database instead of overwriting the record like your code was doing. .
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply


Messages In This Thread
Re: freefile to make appendable a random file? - by MystikShadows - 07-10-2009, 07:36 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)