Child calls parent class and gets error

robbremington

Member
Joined
Jan 6, 2003
Messages
17
Error:
Reference to a non-shared member requires an object reference.
Question:
How do I amend this code to make it work?

Public Class Form1
Inherits System.Windows.Forms.Form

Dim NewClass1 As Class1
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
NewClass1 = New Class1()
Call NewClass1.Class1Sub() ***** Call Class1Sub
End Sub
Public Sub Form1Sub()
TextBox1.Text = "Yes"
End Sub
End Class
Public Class Class1
Public Sub Class1Sub()
Form1.Form1Sub() ****** this line is highlighted in error
End Sub
End Class
 
Code:
Public Class Form1
Inherits System.Windows.Forms.Form

Dim NewClass1 As Class1

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
NewClass1 = New Class1(me)
Call NewClass1.Class1Sub() ***** Call Class1Sub
End Sub
Public Sub Form1Sub()
TextBox1.Text = "Yes"
End Sub
End Class

Code:
Public Class Class1

private mParentObject as Form1

Public Sub New (ByRef myParent as Form1)
 myclass.New()
 mParentObject = myParent
end Sub

Public Sub Class1Sub()
mParent.Form1Sub() 
End Sub
End Class
 
Back
Top