473,385 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

FILELEN() Function slow to update?

I'm having a strange problem using random file access and was wondering if
anyone is aware of why this might be happening. When I write new records to
the file, it seems to take a few seconds before the FILELEN() function to
update with the accurate length. As a test I did the following:

Sub test()
Dim inta As Integer

For inta = 1 To 5

Raffle.TicketsPurchased = inta
Put #20, inta, Raffle
Get #20, inta, Raffle
'Delay (2) Notice this is commented out)
intNumRows = FileLen(App.Path & "\herosraffle.dat") / Len(Raffle)
Say (Str(intNumRows) + " " + Str(Raffle.TicketsPurchased))
Next inta
End Sub
This gave me the following results

1 1
1 2
2 3
3 4
4 5
If I re-run the code with the 2 second delay added in I get

1 1
2 2
3 3
4 4
5 5
Why does it take so long for FILELEN() to update? Is there another way I
can check for how many records are in the file using a different command?
Adding a delay slows down the process this program is performing. Thanks in
advance,
-Keith
Jul 17 '05 #1
2 3519

"Keith Elkin" <ke***@keithelkin.com> wrote in message
news:d%*********************@news4.srv.hcvlny.cv.n et...
I'm having a strange problem using random file access and was wondering if anyone is aware of why this might be happening. When I write new records to the file, it seems to take a few seconds before the FILELEN() function to update with the accurate length. As a test I did the following:

Sub test()
Dim inta As Integer

For inta = 1 To 5

Raffle.TicketsPurchased = inta
Put #20, inta, Raffle
Get #20, inta, Raffle
'Delay (2) Notice this is commented out)
intNumRows = FileLen(App.Path & "\herosraffle.dat") / Len(Raffle)
Say (Str(intNumRows) + " " + Str(Raffle.TicketsPurchased))
Next inta
End Sub
This gave me the following results

1 1
1 2
2 3
3 4
4 5
If I re-run the code with the 2 second delay added in I get

1 1
2 2
3 3
4 4
5 5
Why does it take so long for FILELEN() to update? Is there another way I can check for how many records are in the file using a different command? Adding a delay slows down the process this program is performing. Thanks in advance,
-Keith

Use LOF(#) to get the length of an open file (in your case, LOF(20).
FileLen(Path) is for closed files. You also might want to use FreeFile
to get a file number, instead of using a hard coded value.
Jul 17 '05 #2
Data written to disk is a buffered action, which Windows does when it can.

BTW, the proper formula for calculating the number of records in a random
access file, once it has been opened, is:

totalrecords = LOF(#hfile) \ Len(YourUDT)

Notice too that the division is Integer division, not Floating Point, as
there will never be a decimal.

And conversely, FYI, the next new record for a random access file is always
totalrecords + 1
--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.

There's no place like 127.0.0.1
"Keith Elkin" <ke***@keithelkin.com> wrote in message
news:d%*********************@news4.srv.hcvlny.cv.n et...
: I'm having a strange problem using random file access and was wondering if
: anyone is aware of why this might be happening. When I write new records
to
: the file, it seems to take a few seconds before the FILELEN() function to
: update with the accurate length. As a test I did the following:
:
: Sub test()
: Dim inta As Integer
:
: For inta = 1 To 5
:
: Raffle.TicketsPurchased = inta
: Put #20, inta, Raffle
: Get #20, inta, Raffle
: 'Delay (2) Notice this is commented out)
: intNumRows = FileLen(App.Path & "\herosraffle.dat") / Len(Raffle)
: Say (Str(intNumRows) + " " + Str(Raffle.TicketsPurchased))
: Next inta
: End Sub
:
:
: This gave me the following results
:
: 1 1
: 1 2
: 2 3
: 3 4
: 4 5
:
:
: If I re-run the code with the 2 second delay added in I get
:
: 1 1
: 2 2
: 3 3
: 4 4
: 5 5
:
:
: Why does it take so long for FILELEN() to update? Is there another way I
: can check for how many records are in the file using a different command?
: Adding a delay slows down the process this program is performing. Thanks
in
: advance,
: -Keith
:
:
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Bo Peng | last post by:
Dear list, I have many dictionaries with the same set of keys and I would like to write a function to calculate something based on these values. For example, I have a = {'x':1, 'y':2} b =...
1
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
1
by: Thomas Richards | last post by:
Hi, I have a table with about 70k rows. When I use open table --> return all rows and then edit a field Enterprise Manager then says it has to return the entire result set for the update to take...
12
by: Neil | last post by:
I previously posted re. this, but thought I'd try again with a summary of facts. I have an Access 2000 MDB with a SQL Server 7 back end. There is a view that is linked to the database via ODBC...
3
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
2
by: ThurstonHowl | last post by:
Hello, my task is the following: Input are tables with fields containing strings where the strings are actually delimited lists. For example, one field could contain 'AB|CD|EF|GH' I've...
2
by: Chris | last post by:
I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really...
29
by: Geoff Jones | last post by:
Hi All I hope you'll forgive me for posting this here (I've also posted to ado site but with no response so far) as I'm urgently after a solution. Can anybody help me? I'm updating a table on...
14
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.