<ComClass(NetString.ClassId, NetString.InterfaceId, NetString.EventsId)> _
Public Class NetString
    Public Event Sorted As EventHandler
    Private m_value As String

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "6ED4225F-50EE-453F-87C8-0B29635C9EC0"
    Public Const InterfaceId As String = "03A3E244-F4A2-4F09-BF18-B217F150FDF5"
    Public Const EventsId As String = "062F0AD7-73D9-4DEB-B283-259E55599217"
#End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub

    Public Function Split(ByVal arg As String, Optional ByVal sep As String = " ") As String()
        If Len(sep) <> 1 Then Throw New Exception("Separator musi mieć rozmiar jednego znaku")
        Return arg.Split(CType(sep, Char))
    End Function

    Public Function Join(ByVal arg As Object, Optional ByVal sep As String = " ") As String
        If IsArray(arg) Then
            If arg.Rank <> 1 Then Throw New Exception("Argument musi być tablicą jednowymiarową")
        Else
            Throw New Exception("Pierwszy argument musi być tablicą")
        End If
        Return String.Join(sep, arg)
    End Function

    Public Function Sort(ByVal arg As String, _
      Optional ByVal ascending As Boolean = True) As String
        ' Deklaracja tablicy.
        Dim ar() As String, res As String
        ' Podzielenie ciągu znaków i umieszczenie wyrazów w tablicy.
        ar = arg.Split(" "c)
        ' Posortowanie tablicy.
        ar.Sort(ar)
        ' Odwrócenie porządku na żądanie.
        If Not ascending Then ar.Reverse(ar)
        ' Przekształcenie tablicy z powrotem na ciąg znaków i ustawienie właściwości Value        
        m_value = String.Join(" ", ar)
        ' Wygenerowanie zdarzenia.
        OnSorted()
        ' Zwrócenie wyniku
        Return m_value
    End Function

    Friend Sub OnSorted()
        RaiseEvent Sorted(Me, System.EventArgs.Empty)
    End Sub

    Public ReadOnly Property Value() As String
        Get
            Return m_value
        End Get
    End Property

End Class


