Solved

VB File Errors between tasks in Win2000

Posted on 2006-06-21
4
160 Views
Last Modified: 2010-04-30
We are just converting application workstations to Windows 2000 and there seems to be a 'slowness' letting go of files in Win2000 that was not there in Win95.

Example:

VB Program does a shell to another program (3rd party product) and must wait until the other process completes: it does this by looking at the files created. Here is the code where it failed with an error #53 - File Not Found

    Do While Dir(mstrSwBundleFileName) = ""
        DoEvents
    Loop
    '-- Now wait until its size is non-zero
    Do While FileLen(mstrSwBundleFileName) = 0
        DoEvents
    Loop
   
In the above, only the file length command could get an 'error 53 file not found'


WHY is it that a DIR command returns the file name, then the FILELEN says file not found???
0
Comment
Question by:ruskker
  • 2
4 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16954054

no, file not found applies to the DIR function, because if it's asking what the directory of mstrSwBundleFileName is, and it finds out that mstrSwBundleFileName doesn't exist, then it can't return the directory so it will fail right there. This code should not be executing if mstrSwBundleFileName doesn't exist.
0
 

Author Comment

by:ruskker
ID: 16956273
Not so> The DIR function in VB returns a null string when the file is not found and it is used to test for just that.
By the way, this code has been running fine for 6 years on Win95 and this new behaviour started (inconsistently) on Win2000
0
 
LVL 1

Accepted Solution

by:
tguez earned 500 total points
ID: 17040245
Your code looks ok. I think the problem is that windows 2000 has a file write-caching.  So when files are writtin to the disk, the are not actually written right now, not necessarily.  Windows can cached them in memory, and then write then to disk later.

So, it could be that the dir command finds the file because it has started to be written into the directory table, but has not yet be actually written out into the disk. Or it has been partially written out to the disk, and not finished wirrtien completel,

So when you get to the filelen, you are getting an error.  

This is just an a tought.  I don't know if is correct, just a thought.

You can test if this is correct in a simple way.  Use the debug mode of visual basic.  Step throught the code.  When it goes out of the loop of the dir, then wait a few seconds until you are sure all the disk data has been written, look at the led of the harddirve.  Then continue to step through.  If what I say is correct, if you waited like 30 seconds, and then you do not get an error, then what i said is what actually is happenning.

If you still get the error, then what I said is not true.

But this could actually be the problem.  If the above works with you debug it and wait 30 seconds, perhaps you can just code in a certain time delay between the first loop and second loop.

Tomer

P.S.  Keep me posted what happens.

Another way to speed up the process is the above is correct, there is some API, look in the documentation, then causes windows to flush all write cache of all applictions.  You can call this function between the two loops.  The regular flush works for your program only, not for other programs.
0
 

Author Comment

by:ruskker
ID: 17063341
Tomer

Thanks - I think you are correct. Unfortunately I need to clear the cache of the other process, BUT, what I did was add some sleep time in between the 'dir' and the 'fillen' and after I closed a file to be used by another process. Since I set this time to 10 seconds I have not had the problem in 2 weeks.

Thanks..
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now