Bonjour,

j'ai un petit problème lorsque j’exécute mon code l'erreur suivante est affichée:An unhandled exception of type 'System.IndexOutOfRangeException' occurred in tableau.exe

Additional information: L'index se trouve en dehors des limites du tableau.
en fait j'ai deux forms et j'ai un bouton ajouter qui permet d'ajouter un utilisateur dans un tableau puis dans un deuxième form le contenu de tableau est affiché
Voici mon 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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  Private Sub Ajouter_Click(sender As Object, e As EventArgs) Handles Ajouter.Click
        nbrclients += 1
        ReDim Preserve tab(nbrclients)
        With enr
            .nom = TextBox1.Text()
            .prenom = TextBox2.Text()
            .age = CInt(TextBox3.Text)
        End With
        tab(nbrclients) = enr
        raz()
    End Sub
Private Sub afficher_Click(sender As Object, e As EventArgs) Handles afficher.Click
        Dim x, y As String
        Dim z As Integer
        Dim a As client
        For i = 0 To tab.Length
            MsgBox(tab.Length)
            ' MsgBox(tab(i).nom)
 
            a = tab(i)
            ListBox1.Items.Add(a)
 
            x = tab(i).nom
            ListBox1.Items.Add(x)
            y = tab(i).prenom
            ListBox1.Items.Add(y)
            z = tab(i).age
            ListBox1.Items.Add(z)
            If (i = tab.Length) Then
                End
            End If
 
        Next
    End Sub