|
Post by Piperlester on May 15, 2004 19:24:12 GMT -5
Path$ = "E:\RAY\WEBSITE\DEVT\" 'Replace this with the path to where the 'you saved the data files FileNo = FREEFILE 'Determines the next free file stream RecLen = 114 'The record length of the records
'************************************************************************** 'This piece of code gets each record in turn and displays the whole record
OPEN Path$ + "WEB1.DAT" FOR RANDOM ACCESS READ LOCK READ WRITE AS FileNo LEN = RecLen FIELD FileNo, 114 AS InRecord$
NoRecs = LOF(FileNo) / RecLen FOR InCount = 1 TO NoRecs 'Using a counter like this actualy reads sequentialy GET FileNo, InCount 'Read each record in turn to InRecord$ PRINT InRecord$ 'Any data manipulation can be carried out here NEXT InCount CLOSE FileNo 'Closes the opened file stream
I know what all of this does, and I understand it.. but, you use RecLen = xxx But, the program I am creating is going to be an ongoing database, and I'm trying to figure out how to get the total number from the csv file. If I was doing it with flat text database style... it'd be easy, but the csv format kinks it up.. and I can't find anything on the net about working with a growing csv file.... UNLESS I use another file that just holds the next value for the records... but, that's just one more file (and the fewer files the better).
Any suggestions, or should I just resign myself to this extra little file...(which I'd rather not do).
Thanx dude
|
|
|
Post by brisray on May 15, 2004 20:53:29 GMT -5
If you're writing to CSV files you can't use this method to read them. This is because each field in the database is going to be different lengths, which means each record length is going to be different.
What you need is the INPUT command, as in
OPEN "c:\list.txt" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, Fld1$, Fld2$ '...etc. Read field entries from file. PRINT Fld1$, Fld2$ '... etc. Print the entries on the screen. LOOP CLOSE #1
The EOF(1) is the stream number. This can still be a variable (FREEFILE) as in the code you gave.
The great thing about SDF files is you can go to any record, say how many records in a file and even see if there is a simple error in the database by simple mathematics. For example if the record length is 100 and the file length is 1200 then you know there are 12 records in the database.
Using CSV files, you cannot do this - again because ofthe variable records lengths. What you need to do is either open the file as a binary file (see the QBasic help) and count how many CRLFs there are - test each character for CHR$(10) or CHR$(13). One nice thing about binary files is that you can put up to 32,767 characters at a time into memory. You'll have to keep track of the byte position in the file though and make sure you don't try reading past the end of the file if you use this method.
Another way is to use the something like
OPEN "c:\list.txt" FOR INPUT AS #1 CLS Count=0 DO WHILE NOT EOF(1) INPUT #1, Fld1$, Fld2$ '...etc. Read field entries from file. Count=Count + 1 screen. LOOP CLOSE #1 PRINT "There are ",Count, " records in the database."
For a big database this will take an apreciable length of time.
Ray
|
|