Bonjour,
Bien que j'ait cherché et lu les articles concernant cette erreur, j'arrive pas à le résoudre. 1er temps, quand j'ajoute pas les nouveaux codes, cela compile sans erreur. Après mon insertion, il apparaît l'erreur Error System.NullReferenceException*: 'La référence d'objet n'est pas définie à une instance d'un objet.' mat a été Nothing
Je voudrais coder un jeu de mémoire. Une matrice de chiffres 1-9 va apparaître dans 10 secondes puis l'utilisateur a 20 secondes pour remplir ce qu'il a vu et on va voir qu'il a eu combien de bonnes réponses.

Merci d'avance de votre aide

Voici mon code:

Code VB.NET : 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
Public Class Form1
    Dim list_init As List(Of Integer) = New List(Of Integer)
    Dim list_fill As List(Of Integer) = New List(Of Integer)
 
    Dim Matrix As Integer() = New Integer(8) {1, 2, 3, 4, 5, 6, 7, 8, 9}
    Dim hasard As New Random()
 
    Dim mat As Label
    Dim fill As TextBox
 
    Dim encore As Boolean
 
    Dim nombre_aleatoire As Integer
    Dim List_int As List(Of Integer) = New List(Of Integer)
 
    Public Sub InitMatrix()
        For i As Integer = 0 To 8
            List_int.Add(Matrix(i))
        Next
    End Sub
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MsgBox("Vous avez 10 secondes pour tout mémoriser. Bon courage")
        list_init.Clear()
        list_fill.Clear()
        encore = True
        StartGame()
    End Sub
 
    Private Sub cmd_back_Click(sender As Object, e As EventArgs) Handles cmd_back.Click
 
    End Sub
 
    Private Sub cmd_restart_Click(sender As Object, e As EventArgs) Handles cmd_restart.Click
        list_init.Clear()
        list_fill.Clear()
        encore = True
        StartGame()
    End Sub
 
    Private Sub cmd_exit_Click(sender As Object, e As EventArgs) Handles cmd_exit.Click
        Application.Exit()
    End Sub
 
    Private Sub countdown_Tick(sender As Object, e As EventArgs) Handles countdown.Tick
        countdown.Enabled = True
        countdown.Start()
        countdown.Interval = 1000
        If (lb_timeleft.Text = 0) And (encore = True) Then
            countdown.Stop()
            lb_timeleft.Text = 20
            encore = False
            pnl_mat.Visible = False
            pnl_fil.Visible = True
        ElseIf (lb_timeleft.Text = 0) And (encore = False) Then
            countdown.Stop()
            FillIn()
            Me.Close()
        Else
            lb_timeleft.Text = Val(lb_timeleft.Text) - 1
        End If
    End Sub
 
    Public Sub StartGame()
        pnl_mat.Visible = True
        pnl_fil.Visible = False
        InitMatrix()
 
        lb_timeleft.Text = 10
        For Each element In pnl_mat.Controls
            mat = TryCast(element, Label) 'convertit les labels en 1 seul label
            nombre_aleatoire = hasard.Next(List_int.Count - 1)
            mat.Text = List_int.ElementAt(nombre_aleatoire)
            list_init.Add(Val(mat.Text))
            List_int.RemoveAt(nombre_aleatoire)
        Next
        countdown.Start()
    End Sub
 
    Public Sub FillIn()
        For Each element In pnl_fil.Controls
            fill = TryCast(element, TextBox)
            list_fill.Add(Val(fill.Text))
        Next
 
        Dim correct As Integer = 0
        For i As Integer = 0 To 8
            If (list_init(i) = list_fill(i)) Then
                correct = correct + 1
            End If
        Next
 
        MsgBox("Vous avez ", correct, "correctes réponses")
        Me.Close()
    End Sub
 
    Private Sub cmd_ok_Click(sender As Object, e As EventArgs) Handles cmd_ok.Click
        countdown.Stop()
        FillIn()
    End Sub
End Class