How does 'mybase' work? The syntax is not accepted.

C

COHENMARVIN

I put in the following code in my VB program:

Public Class ClassThree
Private _a As Integer
Public Sub New()
_a = 5
End Sub
Public Sub ClassThreeMethod()
MsgBox("ClassThreeMethod")
End Sub
End Class

Public Class ClassFour
Inherits ClassThree

mybase.ClassThreeMethod
End Class
But the line with 'mybase' is not accepted by the compiler. Neither
is "Mybase.new". What am I doing wrong?
Thanks,
Marvin
 
A

Armin Zingler

I put in the following code in my VB program:

Public Class ClassThree
Private _a As Integer
Public Sub New()
_a = 5
End Sub
Public Sub ClassThreeMethod()
MsgBox("ClassThreeMethod")
End Sub
End Class

Public Class ClassFour
Inherits ClassThree

mybase.ClassThreeMethod
End Class
But the line with 'mybase' is not accepted by the compiler. Neither
is "Mybase.new". What am I doing wrong?


Put the line into a procedure (sub/function, method).


Armin
 
C

Cor Ligthert[MVP]

Marvin-

I am far not as clever as Armin, probably it's better when you next time set
the error text given by the compiler in these messages to the newsgroup.
Probably than more would see it too direct like Armin.

-Cor
 
P

Phill W.

(e-mail address removed) wrote:

But the line with 'mybase' is not accepted by the compiler. Neither
is "Mybase.new". What am I doing wrong?

Mybase is a reference to the [base class] object from which you have
derived /this/ object.

To call a method /on/ that base object, you use Mybase.methodname, which
you've worked out but ... from /where/ do you want to /call/ that [base]
method? Answer: From a method in your derived class, as in

Public Class ClassThree

Public Overrideable Sub Method()

MsgBox("ClassThreeMethod")
End Sub

End Class

Public Class ClassFour
Inherits ClassThree

Public Overrides Sub Method()

MyBase.Method()

MsgBox("ClassFourMethod")
End Sub

End Class

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top