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 45 46 47 48 49 50 51 52 53 54 55
| Option Explicit
Type TContact
Nom As String * 20
Prenom As String * 20
Telephone As String * 15
End Type
Function Existe(Nom As String, Prenom As String) As Boolean
If Dir("c:\Repertoire.txt") = "" Then
Existe = False
Else
Dim f As Integer, Trouve As Boolean, contact As TContact
f = FreeFile
Open "C:\Repertoire.txt" For Random As f Len = Len(contact)
Trouve = False
While Not EOF(f) And Not Trouve
Get #f, , contact
If RTrim$(contact.Nom) = Nom And RTrim$(contact.Prenom) = Prenom Then Trouve = True
Wend
Close f
Existe = Trouve
End If
End Function
Sub Ajoute(Nom As String, Prenom As String, Tel As String)
Dim f As Integer, contact As TContact
contact.Nom = Nom
contact.Prenom = Prenom
contact.Telephone = Tel
f = FreeFile
Open "C:\Repertoire.txt" For Random As f Len = Len(contact)
Seek #f, (LOF(f) \ Len(contact)) + 1
Put #f, , contact
Close f
End If
End Sub
Function Telephone(Nom As String, Prenom As String) As String
Dim f As Integer, contact As TContact, Trouve As Boolean
If Not Existe(Nom, Prenom) Then
Telephone = "Non trouvé..."
f = FreeFile
Open "C:\Repertoire.txt" For Random As f Len = Len(contact)
Trouve = False
While Not EOF(f) And Not Trouve
Get #f, , contact
If RTrim$(contact.Nom) = Nom And RTrim$(contact.Prenom) = Prenom Then
Trouve = True
Telephone = contact.Telephone
End If
Wend
Close f
End If
End Function |
Partager