Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
I'm out of ideas
Message
De
29/01/2006 14:44:21
 
 
À
29/01/2006 14:25:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01091278
Message ID:
01091279
Vues:
18
Hi, Grady

You have several ways to do it.

First would be (if you are using VFP8 or VFP9) to enclose USE in a TRY...CATCH routine.
Try
  Use (pcFileName) In 0 Alias Crime Exclusive
Catch to oError
EndTry

If Vartype(oError) = "O"
*-- An error occured. oError.ErrorNo contains error code, oError.Message contains error message
*-- Do whatever you need to do here.
Else
Index On CrimeDate Tag CrimeDate
*-- There is no need to set order to the tag - Index On automatically sets the order to it.
EndIf
Second would be to intercept the error in Error method of the class/form - the object where this code is located. This apply only if you have this code in a class/form - not applicabile to a PRG procedure file:
Use (pcFileName) In 0 Alias Crime Exclusive
If ThisForm.lErrorOccured
   *-- Do whatever you need to do in case of error
Else
*-- same code as ELSE above
EndIf
Error method of the class where above code is located:
LParameters nError, cMethod, nLine
*-- Show the error message to user, then set the error flag:
ThisForm.lErrorOccured = .T.
Return
Next way would be to not rely on error routines at all; instead, try to open file exclusively:
lnFileHandle = FOpen(&pcFileName, 2)
If lnFileHandle = -1 && it was opened - no one is using it, even shared
  FClose(lnFileHandle)
  Use (pcFileName) In 0 Exclusive Alias Crime
  Index On CrimeDate Tag CrimeDate
Else
  *-- It is open. Show a suggestive message to user and return to GetFile() routine
EndIf
Most probably there are some other ways as well, however, 3 of them should be enough :)

Thank you.



>I am trying to catch the choice of the wrong table name. If a user picks the wrong table, I want to display a messagebox that tells them to choose another file, then on clicking OK the user is returned to the getfile() routine. However, I am getting table is already open errors and must be opened exclusively. I have tried quite a few ideas but the errors persist. There must be a way of doing this. Do you know how?
>
>Here is the main bit of code that I am using to open a table.
>
>
>pcFileName = ""
>pcFileName = Getfile('DBF')
>
>Select 0 && Selects the first available work area
>Use (pcFileName) Alias crime Exclusive
>Select crime
>
>Index On crimedate Tag crimedate && Thanks Sergey
>* Set order to that TAG
>Set  Order To crimedate
>
Grigore Dolghin
Class Software.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform