Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accesing Parent Class

Status
Not open for further replies.

whodaman

Programmer
May 23, 2001
60
CA
Hi all, I've been extreamly stuck trying to figure this out. How would you access the parent class? For example:

Public Class Foo
Dim myInt as Integer
Dim cMoo as Moo

Public Sub main()
myInt = 0
cMoo.changeMyInt()
End Sub
End Class

Public Class Moo [???: inherits Foo]
Public Sub changeMyInt()
myInt = 3
End Sub
End Class

After calling changeMyInt in the main(), I would want to myInt to be 3. How would one do that? In my case I just wrote above, it would create another instance of Foo and only changing that instance. When going back to the Parent Foo, it still would be 0 coming out of Main(). How would one do this?
 
Code:
Public Class Foo
   public shared myInt as Integer
   Dim cMoo as Moo

   Public Sub main()
      myInt = 0
      cMoo.changeMyInt()
   End Sub
End Class

Public Class Moo 
   Public Sub changeMyInt()
     foo.myInt = 3
   End Sub
End Class

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thanks a bunch Christiaan,

I was trying to be a smart ass and keep it simple, but didn't help me too much. What I really am trying to do is:

a form (Form1) calling another class/form (moo.vb). Moo is created from Form1. And Moo wants to change a property of an object in Form1 (i.e. Label1.text).

Since Label1 is defined in Sub InitializeComponent() in Form1.Designer.vb:
Code:
  Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
  End Sub
How would you define Label1 as shared?
 
Whoda, that is where the label is Instantiated. It is declared outside the InitializeComponent sub, just above it. Look for Friend Withevents Label1 as System.Windows.Forms.Label

change that to:
Protected Withevents Label1 as System.Windows.Forms.Label

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Now Rick this seems to be the third time today you said that.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
4th if you include the FAQ ;)

You'd think people are actually listening to the generated warning message or something.

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
I've never like changing a control's properties from another form/class it has created. I would end up using an event, but that's just me:

Main Form
Code:
Sub SomeRoutine
     Dim sf As New SubForm()
     AddHandler(sf.ChangeText(), AdressOf ChangeText)
     sf.Show()
End Sub

Sub ChangeText(ByVal NewText As String)
     Label1.Text = NewText
End Sub

Sub Form
Code:
Public Event ChangeText(ByVal NewText As String)
.....
Sub SomeRoutine
     RaiseEvent ChangeText(SomeText)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top