Hi there,
I have a class with the following method in it:
I have a button in my frmMain form with the following code:Code:Public Class RedControlTracker Dim frmainInst As New frmMain Sub New() ' Constructor GetRedControl() End Sub Public Function GetRedControl() As Control Dim c As Control For Each c In frmainInst.Panel3.Controls If c.BackColor.Equals(Color.Red) Then Return c End If Next End Function End Class
When I press the button I get the following error:Code:Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim c As New RedControlTracker MessageBox.Show("Name of the Red Control is: " & c.GetRedControl.Name) End Sub
Object reference not set to an instance of an object
What am I doing wrong?
There is a control with red backround in my Panel3 control. I have not had this error before, probably because my knowledge of classes is very limited. I can get it to work, doing all the coding in my frmMain (form) class, but it is getting kind of crouded.
Thank you for any help,
Hans




Reply With Quote