Bonjour à tous,
j'aimerais crééer un repertoire téléphonique, et je voudrais savoir si quelqu'un aurait l'aimabilité de m'indiquer où sont mes erreurs, si il y en a (il doit y en avoir plein).
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
If Not Existe(Nom, Prenom) Then
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
Donc voici le code que j'ai fait pour le moment, je voudrais donc savoir si c'est bon, pour pouvoir continuer tranquillement.
Merci de votre compréhension.

