BASIC OOP QUESTION

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Public Class HSBC

Inherits Class1


Dim root As XmlElement

Dim node As XmlElement

Dim altnode As XmlElement

Dim myxml As New XmlDocument





Dim wr As New WR



root = myxml.CreateElement("CC5Request")



myxml.AppendChild(root)

node = myxml.CreateElement("Name")

node.InnerText = PosName



there is a notification node and myxml variables which is declaration
expected.



when i put that piece of code in a method it is ok.



I want to inherit from another class and add some piece of code to that
code. When i put it in a function is it possible to add some content to
that code.



How can i solve it ?
 
in said:
Public Class HSBC
Inherits Class1
Dim root As XmlElement
Dim node As XmlElement
Dim altnode As XmlElement
Dim myxml As New XmlDocument
Dim wr As New WR

Putting declarations outside of a method like this makes all of these
variables members of the HSBC class.
I'm not sure if that's what you intended here.
root = myxml.CreateElement("CC5Request")
myxml.AppendChild(root)
node = myxml.CreateElement("Name")
node.InnerText = PosName

(1) This is functional code and *must* go inside a method.
(2) PosName is not defined.
Do you have Option Explicit turned on?
when i put that piece of code in a method it is ok.
Good...

I want to inherit from another class and add some piece of code to that
code. When i put it in a function is it possible to add some content to
that code.

Sounds like you want to "extend" the base class method.

"Overriding" is the .Net/OO term for "unplugging" the base class
implementation of a method and replacing it with a different
implementation in a subclass. This is one of the basics of Polymorphism.

"Extending" is the word /I/ use for both "overriding" /and/ "reusing"
the base implementation of a method:

Class base
' Here's an "extendable" method
Public Overridable Sub BuildDoc() ' marked as Overridable
' which does some stuff
m_xml = New XmlDocument
. . .
End Sub

' We're holding an Xml document in this class, but our
' subclasses need to get access to it, so
Protected ReadOnly Property Doc() as XmlDocument
Get
Return m_xml
End Get
End Property

' And here's the document
Private m_xml As XmlDocument

End Class

Class derived
Inherits base

' Here's the "extending" method
Public Overrides Sub BuildDoc()
' First, reuse the base class implementation
MyBase.BuildDoc()

' Then, add some new bits just for this subclass
MyBase.Doc.CreateElement( "NewNode" )

End Sub

End Class

HTH,
Phill W.
 
In my Overridable method a have instance from another class and other
methods. I need to call some methods too. Can you give me a link to learn
that topic effectively.
 
Back
Top