Bonjour tout le monde,

J'ai un petit programme VB6 qui permet de consulter les données d'un carnet d'adresse mais aussi d'ajouter des nouvelles personnes.

Je ne comprends pas bien ce code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Private Sub AfficherEnregistrement(Optional ByVal IndiceMiseAJour As Integer = -1)
'If rsTable.BOF Or rsTable.EOF Then au cas où on ajoute un enregistrement avant le tout premier ou après le tout dernier enregistrement
'ça sert surtout à ajouter un enregistrement, l'ajout se fait après le dernier, on est alors en EOF
'On met les champs à rien pour pouvoir y indiquer une nouvelle entrée
    If rsTable.BOF Or rsTable.EOF Then
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampNom) Then textChamp(ChampNom).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampPrenom) Then textChamp(ChampPrenom).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampAdresse) Then textChamp(ChampAdresse).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampLocalite) Then comboChamp(ChampLocalite).ListIndex = -1
    Else
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampNom) Then textChamp(ChampNom).Text = rsTable("nom")
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampPrenom) Then textChamp(ChampPrenom).Text = "" & rsTable("prenom")
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampAdresse) Then textChamp(ChampAdresse).Text = "" & rsTable("adresse")
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampLocalite) Then BDSelectionnerParId rsTable("ref_localite"), comboChamp(ChampLocalite)
    End If
Je comprends que cette partie de code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
If rsTable.BOF Or rsTable.EOF Then
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampNom) Then textChamp(ChampNom).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampPrenom) Then textChamp(ChampPrenom).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampAdresse) Then textChamp(ChampAdresse).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampLocalite) Then comboChamp(ChampLocalite).ListIndex = -1
c'est quand on ajoute un nouvel enregistrement, ce dernier enregistrement se met à la fin et est donc en EOF.

L'autre partie de code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
Else
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampNom) Then textChamp(ChampNom).Text = rsTable("nom")
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampPrenom) Then textChamp(ChampPrenom).Text = "" & rsTable("prenom")
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampAdresse) Then textChamp(ChampAdresse).Text = "" & rsTable("adresse")
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampLocalite) Then BDSelectionnerParId rsTable("ref_localite"), comboChamp(ChampLocalite)
    End If
Je comprends que cette partie de code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
If rsTable.BOF Or rsTable.EOF Then
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampNom) Then textChamp(ChampNom).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampPrenom) Then textChamp(ChampPrenom).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampAdresse) Then textChamp(ChampAdresse).Text = ""
        If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampLocalite) Then comboChamp(ChampLocalite).ListIndex = -1
Met les zones de textes à vide afin de pouvoir encoder une nouvelle personne.

Ce que je ne comprends pas c'est ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
 If (IndiceMiseAJour = -1) Or (IndiceMiseAJour = ChampLocalite)
Je ne sais pas d'où vient "IndiceMiseAJour", je sais que c'est un paramètre optionnel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
Private Sub AfficherEnregistrement(Optional ByVal IndiceMiseAJour As Integer = -1)
Mais nulle part, la valeur ne vaut autre chose que -1.

Sauriez-vous me dire à quoi cela sert ?

Je vous en remercie d'avance.

beegees

PS: je vous laisse le code afin d'y voir plus claire