Solved

VB File Errors between tasks in Win2000

Posted on 2006-06-21
4
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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