Results 1 to 3 of 3

Thread: Sorting Text

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    6

    Sorting Text

    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:
    1. Dim ln, curline, letter As String
    2.         Dim i, charsInFile, lineCount As Short
    3.         lineCount = 0
    4.         charsInFile = tb1.Text.Length
    5.         For i = 0 To charsInFile - 1
    6.             letter = tb1.Text.Substring(i, 1)
    7.             If letter = Chr(13) Then
    8.                 lineCount += 1
    9.                 i += 1
    10.             End If
    11.         Next i
    12.         ReDim strArray(lineCount)
    13.         curline = 1
    14.         ln = ""
    15.         For i = 0 To charsInFile - 1
    16.             letter = tb1.Text.Substring(i, 1)
    17.             If letter = Chr(13) Then
    18.                 curline = curline + 1
    19.                 i += 1
    20.                 ln = ""
    21.             Else
    22. '==================================================================
    23.                 ln = ln & letter
    24.                 strArray(curline) = 1'<---Here is the prolem!
    25. 'And this is the message I'm getting: Additional information: Index was outside the bounds of the array.
    26. '==================================================================
    27.             End If
    28.         Next i
    29.         ShellSort(strArray, lineCount)
    30.         tb1.Text = ""
    31.         curline = 1
    32.         For i = 1 To lineCount
    33.             tb1.Text = tb1.Text & strArray(curline) & vbCrLf
    34.             curline += 1
    35.         Next i
    36.         tb1.Select(1, 0)

    This I have in a module:
    VB Code:
    1. Sub ShellSort(ByRef sort() As String, ByVal numOfElements As Short)
    2.         Dim temp As String
    3.         Dim i, j, span As Short
    4.         span = numOfElements \ 2
    5.         Do While span > 0
    6.             For i = span To numOfElements - 1
    7.                 For j = (i - span + 1) To 1 Step -span
    8.                     If sort(j) <= sort(j + span) Then Exit For
    9.                     temp = sort(j)
    10.                     sort(j) = sort(j + span)
    11.                     sort(j + span) = temp
    12.                 Next j
    13.             Next i
    14.             span = span \ 2
    15.         Loop
    16.     End Sub
    I would really appreciate some help with this.
    Thanks!!!
    Last edited by Kramer3; Mar 13th, 2004 at 04:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width