I have been looking at (reading) how to sort text and tryed to implement it into my Text Editor but for some reason it will not work![]()
It is constantly showing me the same error.
Here is the Code:
VB Code:
Dim ln, curline, letter As String Dim i, charsInFile, lineCount As Short lineCount = 0 charsInFile = tb1.Text.Length For i = 0 To charsInFile - 1 letter = tb1.Text.Substring(i, 1) If letter = Chr(13) Then lineCount += 1 i += 1 End If Next i ReDim strArray(lineCount) curline = 1 ln = "" For i = 0 To charsInFile - 1 letter = tb1.Text.Substring(i, 1) If letter = Chr(13) Then curline = curline + 1 i += 1 ln = "" Else '================================================================== ln = ln & letter strArray(curline) = 1'<---Here is the prolem! 'And this is the message I'm getting: Additional information: Index was outside the bounds of the array. '================================================================== End If Next i ShellSort(strArray, lineCount) tb1.Text = "" curline = 1 For i = 1 To lineCount tb1.Text = tb1.Text & strArray(curline) & vbCrLf curline += 1 Next i tb1.Select(1, 0)
This I have in a module:
I would really appreciate some help with this.VB Code:
Sub ShellSort(ByRef sort() As String, ByVal numOfElements As Short) Dim temp As String Dim i, j, span As Short span = numOfElements \ 2 Do While span > 0 For i = span To numOfElements - 1 For j = (i - span + 1) To 1 Step -span If sort(j) <= sort(j + span) Then Exit For temp = sort(j) sort(j) = sort(j + span) sort(j + span) = temp Next j Next i span = span \ 2 Loop End Sub
Thanks!!!




Reply With Quote