VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to implement inheritance in VB.NET

by Hari Reddy (5 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 12th August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

How to implement inheritance in VB.NET

API Declarations



Class1 : CLine (which is Base Class)
Class2 : CInheritcline (Which is derived class of CLine)
Module : General (Which has execution code)


Rate How to implement inheritance in VB.NET




Option Strict On 'Strict parameters type checking
Option Explicit On  'Variable must be defined this is be default

Imports System.Console 'imports the console class which has methods to writetoline and etc

Module General
    
    Public Sub Main()
        
        Dim aLineInherit As New CInheritcline()
        
        With aLineInherit
            
            .Line = "Digital Publishing Solutions Koregoan Park Pune"
            
            WriteLine(.Length)
            WriteLine(.GetWord())
            WriteLine(.GetWord(5))
            WriteLine(.GetWord("lishing"))
            
            .ShowText() 'this displays the Line text
            
        End With
        
        aLineInherit = Nothing
        
    End Sub
    
End Module


'Paste the following code CLine class

Option Explicit On 
Option Strict On

Public Class CLine
    
    Private m_sLine As String
    
    Public Property Line() As String
        
        Get
            Return m_sLine
        End Get
        
        Set
            m_sLine = Value
        End Set
        
    End Property
    
    ReadOnly Property Length() As Long
        
        Get
            Return m_sLine.Length
        End Get
        
    End Property
    
    Public Overloads Function GetWord() As String
        
        Dim astrWords() As String
        
        astrWords = m_sLine.Split(" ".ToCharArray())
        
        Return (astrWords(0))
        
    End Function
    
    Public Overloads Function GetWord(ByVal Position As Integer) As String
        Dim astrWords() As String
        
        astrWords = m_sLine.Split(" ".ToCharArray())
        
        If Position > astrWords.Length Then
            Return ("")
            
        Else
            Return (astrWords(Position - 1))
        End If
        
    End Function
    Public Overloads Function GetWord(ByVal Search As String) As String
        Dim astrWords() As String
        Dim intLoop As Integer
        
        astrWords = m_sLine.Split(" ".ToCharArray())
        
        For intLoop = 0 To astrWords.Length - 1
            If astrWords(intLoop).IndexOf(Search) > -1 Then
                Exit For
            End If
        Next
        If intLoop < astrWords.Length Then
            Return (astrWords(intLoop))
        End If
    End Function
    
End Class

'Paste the following code in CInheritcline
Option Explicit On 
Option Strict On

Imports Microsoft.VisualBasic 'Import all features and functions of VB6

Public Class CInheritcline
    
    Inherits CLine
    
    Public Sub ShowText() 'this additional method in the derived class
        
        MsgBox(MyBase.Line) 'here mybase is CLine class
        
    End Sub
    
End Class


Download this snippet    Add to My Saved Code

How to implement inheritance in VB.NET Comments

No comments have been posted about How to implement inheritance in VB.NET. Why not be the first to post a comment about How to implement inheritance in VB.NET.

Post your comment

Subject:
Message:
0/1000 characters