Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Test for Open File
Message
From
21/02/2006 12:13:30
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01097778
Message ID:
01097784
Views:
12
>I set up the following code, but have not yet done the loop for it. My problem is that when I was testing this, the return value was -1, which means that I would not be able to open the file. However, within a split second I opened it manually, so I don't know if I can trust this FOPEN function to return a true value. My purpose is to keep my program from bombing if I cannot successfully open the file exclusively and then have the user wait until the file can be opened exclusively.
>
>[Tedious explanation: The same filename is used earlier in the program, but is actually a copy of the one on our network and we open it on drive c:\ locally. In regard to the file below it is the one on the network and I need to update it after closing the file by the same name on the local drive.]
>
>Here's my code, without the loop yet. (I'll do the loop later.)
>
>
>*** 02/21/2006 Cecil Champenois. We need to set this up so that the user
>*** waits here until the following Production file is able to be opened.
>LOCAL lcFileName, lcMessageText AS Character
>LOCAL lnSuccess AS Number
>#DEFINE NREADWRITE 12
>lcFileName="E:\PRODUCTION\DATA\PRODUCTION"
>lnSuccess=FOPEN(lcFileName, NREADWRITE)
>=FCLOSE(lcFileName)
>lcMessageText="Field is in use by another user."
>lcTitleText  ="Please wait for file to be available"
>IF lnSuccess < 0
>	MESSAGEBOX(lcMessageText, 0, lcTitleText)
>ELSE
>	* The file is not being used by anyone so, open it now.
>	USE (lcFileName) EXCLUSIVE ALIAS PROD_E
>ENDIF
>
Cecil,
You can trust fopen(). However your code has a typo + you opening the file in a split second later with "use ...exclusive" line doesn't mean that you're using it exclusively. Check with isexclusive(). You can also code like:
local llHadError
on error llHadError = .t.
use (m.lcFileName) exclusive alias prod_e
on error
if !m.llHadError and IsExclusive('prod_e')
...
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform