Finding last record in file

robgraham
05-22-2003, 05:57 AM
My program will be used to enter data for about 2000 customers. An append file will have a sequence number and some data recorded. Is there an easy way to access the last record so that I can find out the number of customers from the sequence number without having to loop through every record.

Rob

almostsane
05-22-2003, 07:14 AM
i'm not sure how to do it.

there is kinda a "cheat" way to do it.... have a counter in a sperate file, which you simply update each time you add a new customer.. kinda like


'this is when adding a new customer
open "counter.txt" for input as #1

input #1, x ' get old value of X
close #1
x = x +1 ' adds 1 to x
open "Counter.txt" for output as #1
write #1, x


this replaces the value each time a new customer is added.

then if you wanna find the last number simply



open "counter.txt" for input as #1

input #1, x ' get value of X
close #1
msgbox (x)

Flyguy
05-22-2003, 07:38 AM
Do these records all have the same size?
If so you can just jump to the end of the file - the length of the record, using the Seek statement.

I use the same kind of trick as almostsane, but I always use the first 4 bytes to store a long value.

robgraham
05-23-2003, 07:02 AM
Thanks guys - hoped there might have been something built in that did this. Will just have to do it by coding !

Cheers

Rob

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum