codefalse
Messages postés1123Date d'inscriptionmardi 8 janvier 2002StatutModérateurDernière intervention21 avril 2009
-
23 janv. 2002 à 15:19
Makabey
Messages postés152Date d'inscriptionmercredi 27 juin 2001StatutMembreDernière intervention11 juillet 2002
-
23 janv. 2002 à 21:10
Bonjour,
j'ouvre un fichier avec input et je met on error goto erreur pour le cas ou le ficheir n'exste pas, mais pour lui, il n'existe jamais, il ignore ce qui a apres open et va directement a erreur
si tu pourrait m'aider!
Voici le code :
Private Sub testnom()
On Error GoTo prout
Open "c:\nom.txt" For Input As #1
Input #1, nom
Close #1
demar
prout:
Close
Open "c:\nom.txt" For Output As #1
Print #1, "nom"
Close #1
Open "c:\nom.txt" For Input As #1
Input #1, nom
Close #1
demar
Resume Next
End Sub
et ce con va directement dans le label erreur, qui a la base est destiné a etre si le fichier n'existe pas !
Makabey
Messages postés152Date d'inscriptionmercredi 27 juin 2001StatutMembreDernière intervention11 juillet 20021 23 janv. 2002 à 21:10
Essaie ceci:
Private Sub testnom()
Dim Nom1 As String
Dim NumFich As Integer
On Error GoTo prout
NumFich = FreeFile
Open "c:\nom.txt" For Input As #NumFich
Input #NumFich, Nom1
Close #NumFich
Debug.Print Nom1
''demar
Exit Sub
prout:
Select Case Err.Number
'76: Path Not Found
Case 76
Debug.Print "Chemin inexistant..."
'53: File Not Found
Case 53
Open "c:\nom.txt" For Output As #NumFich
Print #NumFich, "nom"
Close #NumFich
Open "c:\nom.txt" For Input As #NumFich
Debug.Print "Fichier inexistant!"
Resume Next
Case Else
MsgBox "Erreur #" & Trim$(Str$(Err.Number)) & " (" & Err.Description & "), non traitée..."
End Select
End Sub