VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to implement method overloading 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 method overloading in VB.NET

API Declarations



CLine class contains GetWord method in three 3 type of implementions.



Rate How to implement method overloading in VB.NET



Module General
    
    Public Sub Main()
        
        Dim aLine As New CLine()
        
        With aLine
            
            .Line = "Digital Publishing Solutions Koregoan Park Pune"
            System.Console.WriteLine(.Length)
            System.Console.WriteLine(.GetWord())
            System.Console.WriteLine(.GetWord(5))
            System.Console.WriteLine(.GetWord("lishing"))
            
        End With
        
        aLine = Nothing
        
    End Sub
    
End Module

'Paste the following code in CLine class. here u will have to create class as name CLine

Public Class CLine
    
    Private m_sLine As String
    Private m_lLength As Long
    
    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 Microsoft.VisualBasic.Len(m_sLine)
        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



Download this snippet    Add to My Saved Code

How to implement method overloading in VB.NET Comments

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

Post your comment

Subject:
Message:
0/1000 characters