1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
Module Répertoire
Sub Main()
Dim Nom, Prénom, Tel
Nom = "Drollet"
Prénom = "Patrice"
Tel = "0321512998"
ajoute(Nom, Prénom, Tel)
End Sub
Sub ajoute(ByVal Nom As String, ByVal Prénom As String, ByVal Tel As String)
If Not existe(Nom, Prénom) Then
Dim FichierRepertoire = FreeFile()
FileOpen(FichierRepertoire, "C:\Repertoire.txt", OpenMode.Append)
WriteLine(FichierRepertoire, Nom, Prénom, Tel)
FileClose(FichierRepertoire)
Else
MsgBox("Le nom existe déjà dans le fichier !!")
End If
End Sub
Function existe(ByVal Nom As String, ByVal Prénom As String) As Boolean
Dim FichierRepertoire = FreeFile()
FileOpen(FichierRepertoire, "C:\Repertoire.txt", OpenMode.Input)
Dim value = String.Empty
Dim found As Boolean
While Not EOF(FichierRepertoire)
If LineInput(FichierRepertoire).StartsWith(Chr(34) & Nom & Chr(34) & "," & Chr(34) & Prénom & Chr(34)) Then
found = True
Exit While
End If
End While
FileClose(FichierRepertoire)
Return found
End Function
End Module |
Partager