How to create an overrides Sub or Function in VB.NET IDE?

G

Guest

I need something likes as when I create an event procedure.
I can use top-left and top-right dropdown list of code editor
to select object and its exposed events respectively.

Then, the IDE, automatically paste the function
header (signature) for me.

But I can't find a way to see list of Sub or Function
that I can overrides such as ToString Function.

Please guide me.
TIA.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?U3VycmVhbGlzdA==?= said:
I need something likes as when I create an event procedure.
I can use top-left and top-right dropdown list of code editor
to select object and its exposed events respectively.

Then, the IDE, automatically paste the function
header (signature) for me.

But I can't find a way to see list of Sub or Function
that I can overrides such as ToString Function.

Select "(Overrides)" in the left combobox, and then the method you want
to override in the right combobox (works for 'ToString').
 
G

Guest

It's work fine for a Form.

But how about if I create my own class?
It's not has (Overrides) for me.

Thanks.
Surrealist.
 
P

Phill. W

Surrealist said:
It's work fine for a Form.

But how about if I create my own class?
It's not has (Overrides) for me.

I suspect you only see an Overrides section when there's something
to override. You need to declare the methods in your Base class as
Overridable, as in

[Base1.vb]
Public Class Base1
Public Overridable Sub Pop()
. . .
End Sub
End Class

[Derived1.vb]
Public Class Derived1
Inherits Base1

Public Overrides Sub Pop()
. . .
End Sub

End Class

HTH,
Phill W.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?U3VycmVhbGlzdA==?= said:
It's work fine for a Form.

But how about if I create my own class?
It's not has (Overrides) for me.

Mark the methods as 'Overridable'.
 
G

Guest

Thanks for all that participate in solving my problem.

I still have a question that did not solved.
I'll list my understanding and please let me know if somethings incorrect.

- Every class must has a based class and its root must be System.Object.
- In System.Object has ToString method that overridable.
- So, If I declare a class without Inherits clause.
Does it inherits from System.Object by default? Why it does not show
(Overrides) section in "Class Name" dropdown list.

Public Class Person
Public FirstName, LastName As String

' ---- How can I create an overrides function of System.Object.ToString here,
' ---- with helpping from Visual Studio .Net IDE?

' ---- Which I currently know is _manually_ type the function header
' ---- with a correct signature as this:
Public Overrides Function ToString() As String
Return FirstName & " " & LastName
End Function

End Class


Thank again,
Surrealist.
 
G

Guest

Thanks for all that participate in solving my problem.

I still have a question that did not solved.
I'll list my understanding and please let me know if somethings incorrect.

- Every class must has a based class and its root must be System.Object.
- In System.Object has ToString method that overridable.
- So, If I declare a class without Inherits clause.
Does it inherits from System.Object by default? Why it does not show
(Overrides) section in "Class Name" dropdown list.

Public Class Person
Public FirstName, LastName As String

' ---- How can I create an overrides function of System.Object.ToString here,
' ---- with helpping from Visual Studio .Net IDE?

' ---- Which I currently know is _manually_ type the function header
' ---- with a correct signature as this:
Public Overrides Function ToString() As String
Return FirstName & " " & LastName
End Function

End Class


Thank again,
Surrealist.

Phill. W said:
Surrealist said:
It's work fine for a Form.

But how about if I create my own class?
It's not has (Overrides) for me.

I suspect you only see an Overrides section when there's something
to override. You need to declare the methods in your Base class as
Overridable, as in

[Base1.vb]
Public Class Base1
Public Overridable Sub Pop()
. . .
End Sub
End Class

[Derived1.vb]
Public Class Derived1
Inherits Base1

Public Overrides Sub Pop()
. . .
End Sub

End Class

HTH,
Phill W.
Thanks.
Surrealist.
 
G

Guest

Thanks for all that participate in solving my problem.

I still have a question that did not solved.
I'll list my understanding and please let me know if somethings incorrect.

- Every class must has a based class and its root must be System.Object.
- In System.Object has ToString method that overridable.
- So, If I declare a class without Inherits clause.
Does it inherits from System.Object by default? Why it does not show
(Overrides) section in "Class Name" dropdown list.

Public Class Person
Public FirstName, LastName As String

' ---- How can I create an overrides function of System.Object.ToString here,
' ---- with helpping from Visual Studio .Net IDE?

' ---- Which I currently know is _manually_ type the function header
' ---- with a correct signature as this:
Public Overrides Function ToString() As String
Return FirstName & " " & LastName
End Function

End Class


Thank again,
Surrealist.



Phill. W said:
Surrealist said:
It's work fine for a Form.

But how about if I create my own class?
It's not has (Overrides) for me.

I suspect you only see an Overrides section when there's something
to override. You need to declare the methods in your Base class as
Overridable, as in

[Base1.vb]
Public Class Base1
Public Overridable Sub Pop()
. . .
End Sub
End Class

[Derived1.vb]
Public Class Derived1
Inherits Base1

Public Overrides Sub Pop()
. . .
End Sub

End Class

HTH,
Phill W.
Thanks.
Surrealist.
 
G

Guest

Once you declare the new class, and do not explicatly inherit from System.Object, then the Overridable function of System.Object is hidden. Not sure if it is an IDE thing or a Framework thing.

I do know that you can write your own ToString function without marking it as Overrides, so I would tend to think that it is a Framework thing. I suspect that if you do not explicately inherit from System.Object that there is code to implecitely shadow the ToString, Equals and GetHashCode functions if you specify them otherwise provide the default implementation.

HTH
 

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