Public Class Form1
Private firstClicked As Label = Nothing
Private secondClicked As Label = Nothing
Private random As New Random
Private icons =
New List(Of String) From {"!", "!", "N", "N", ",", ",", "k", "k", "b", "b", "v", "v", "w", "w", "z", "z"}
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
AssignIconsToSquares()
End Sub
Private Sub AssignIconsToSquares()
For Each Control In TableLayoutPanel1.Controls
Dim iconLabel = TryCast(Control, Label)
If iconLabel IsNot Nothing Then
Dim randomNumber = random.Next(icons.Count)
iconLabel.Text = icons(randomNumber)
iconLabel.ForeColor = iconLabel.BackColor
icons.RemoveAt(randomNumber)
End If
Next
End Sub
Private Sub label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click, Label9.Click, Label8.Click, Label7.Click, Label6.Click, Label5.Click, Label4.Click, Label3.Click, Label2.Click, Label16.Click, Label15.Click, Label14.Click, Label13.Click, Label12.Click, Label11.Click, Label10.Click, Label1.Click
If Timer1.Enabled Then Exit Sub
Dim clickedLabel1 = TryCast(sender, Label)
If clickedLabel1 IsNot Nothing Then
If clickedLabel1.ForeColor = Color.Black Then Exit Sub
If firstClicked Is Nothing Then
firstClicked = clickedLabel1
firstClicked.ForeColor = Color.Black
Timer1.Start()
Exit Sub
End If
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
firstClicked.ForeColor = firstClicked.BackColor
secondClicked.ForeColor = secondClicked.BackColor
firstClicked = Nothing
secondClicked = Nothing
End Sub
End Class
Hi, this is the code for a matching game that I am making following a tutorial from here: http://msdn.microsoft.com/en-us/library/vstudio/dd553235(v=vs.100).aspx
My problem is I get the error:
A first chance exception of type 'System.NullReferenceException'
occurred in Matching Game.exe
Which points to the line:
secondClicked.ForeColor = secondClicked.BackColor
Can someone help me out here please?