Public Function GetIndexFromString(ByVal sSuch As String, _
Optional ByVal nMode As Byte = 0, _
Optional vErg As Variant) As Long
Dim n As Long
Dim i As Long
Dim s As String
Dim arS() As Long
If tmpText = "" Then Exit Function
n = SendMessage(tmphWnd, EM_GETLINECOUNT, 0, 0&)
For i = 0 To n - 1
s = Space(tmpBuffer)
SendMessage tmphWnd, EM_GETLINE, i, ByVal s
If tmpCaseSens Then
If sSuch = Trim(s) Then
GetIndexFromString = i
If nMode = 0 Then Exit For
ReDim Preserve arS(i)
arS(i) = i
End If
Else
If UCase(sSuch) = UCase(Trim(s)) Then
GetIndexFromString = i
If nMode = 0 Then Exit For
ReDim Preserve arS(i)
arS(i) = i
End If
End If
Next
If nMode > 0 Then
vErg = arS()
GetIndexFromString = UBound(arS())
End If
End Function
Function GetStringFromIndex(ByVal nIndex As Long) As String
Dim s As String
If nIndex < 0 Then Exit Function
s = Space(tmpBuffer)
n = SendMessage(tmphWnd, EM_GETLINECOUNT, 0, 0&)
SendMessage tmphWnd, EM_GETLINE, nIndex, ByVal s
GetStringFromIndex = Trim(s)
End Function
Public Property Get Count() As Long
Count = SendMessage(tmphWnd, EM_GETLINECOUNT, 0, 0&)
End Property
Public Property Get CaseSensitive() As Boolean
CaseSensitive = tmpCaseSens
End Property
Public Property Let CaseSensitive(ByVal vNewValue As Boolean)
tmpCaseSens = vNewValue
End Property
Public Property Get Delimeter() As String
Delimeter = tmpDelimeter
End Property
Public Property Let Delimeter(ByVal vNewValue As String)
tmpDelimeter = vNewValue
End Property
Public Sub ReplaceStringByString(ByVal sSuch As String, sRepl As String, _
Optional nSensitive As Byte = 0)
Dim n As Long
Dim mergeSens As Boolean
Dim x As Long
Dim y As Long
mergeSens = tmpCaseSens
If nSensitive = 1 Then tmpCaseSens = True
n = GetIndexFromString(sSuch)
x = SendMessage(tmphWnd, EM_LINEINDEX, n, 0&)
y = SendMessage(tmphWnd, EM_LINELENGTH, x, 0&)
SendMessage tmphWnd, EM_SETSEL, x, ByVal (x + y)
SendMessage tmphWnd, EM_REPLACESEL, False, ByVal sRepl
tmpCaseSens = mergeSens
End Sub
Public Sub ReplaceStringByIndex(ByVal nIndex As Long, sRepl As String)
Dim x As Long, y As Long
If nIndex > SendMessage(tmphWnd, EM_GETLINECOUNT, 0, 0&) Then Exit Sub
If nIndex < 0 Then Exit Sub
x = SendMessage(tmphWnd, EM_LINEINDEX, nIndex, 0&)
y = SendMessage(tmphWnd, EM_LINELENGTH, x, 0&)
SendMessage tmphWnd, EM_SETSEL, x, ByVal (x + y)
SendMessage tmphWnd, EM_REPLACESEL, False, ByVal sRepl
End Sub
Public Function SetBookMark(ByVal nBook As Variant) As Variant
Dim n As Long, x As Long, y As Long
If Not IsNumeric(nBook) Then
n = GetIndexFromString(nBook)
x = SendMessage(tmphWnd, EM_LINEINDEX, n, 0&)
y = SendMessage(tmphWnd, EM_LINELENGTH, x, 0&)
SendMessage tmphWnd, EM_SETSEL, x, ByVal (x + y)
SetBookMark = n
Else
x = SendMessage(tmphWnd, EM_LINEINDEX, nBook, 0&)
y = SendMessage(tmphWnd, EM_LINELENGTH, x, 0&)
SendMessage tmphWnd, EM_SETSEL, x, ByVal (x + y)
SetBookMark = GetStringFromIndex(CLng(nBook))
End If
End Function
Public Property Get GetBookMark() As Long
Dim x As Long, y As Long
SendMessage tmphWnd, EM_GETSEL, VarPtr(x), ByVal VarPtr(y)
GetBookMark = SendMessage(tmphWnd, EM_LINEFROMCHAR, x, 0&)
End Property
Public Sub Sort(Optional ByVal nMode As Byte = 0)
Dim x As Long, y As Long
Dim xx As Long
Dim a As String, b As String
xx = SendMessage(tmphWnd, EM_GETLINECOUNT, 0, 0&)
For x = 0 To xx
For y = x To xx + 1
a = GetStringFromIndex(x)
b = GetStringFromIndex(y)
If b = "" Then Exit Sub
Select Case nMod
Case 0
If UCase$(a) > UCase(b) Then
ReplaceStringByIndex y, a
ReplaceStringByIndex x, b
End If
Case 1
If UCase$(a) < UCase(b) Then
ReplaceStringByIndex y, a
ReplaceStringByIndex x, b
End If
End Select
Next y, x
End Sub 0 |