|
-
Mar 13th, 2004, 04:00 AM
#1
Thread Starter
New Member
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:
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:
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
I would really appreciate some help with this.
Thanks!!!
Last edited by Kramer3; Mar 13th, 2004 at 04:03 AM.
-
Mar 14th, 2004, 12:11 AM
#2
New Member
put a break on that line so when your code is executing it will pause on that line, then you can see what the value of curline is, what is happening is you have an array (strArray), and it has a certain length to it. if it's length is 2:
strArray(0) & strArray(1) and you try to do this: strArray(2) = "something", then you will pull that same error that you are receiving.
something you can add to that to stop getting that error (but sounds like you have a bug with the logic, I am having a slightly hard time following it) is the following:
Instead of strArray(curline) = 1
make it:
if strArray.length <= curline then strArray(curline) = 1
That will cause THAT exception to stop popping up, but probably create another bug somewhere else.
Basically in a nutshell though, the value of curline is greater then the length of strArray, gotta stop that from happening.
-
Oct 27th, 2004, 11:04 AM
#3
New Member
Kramer3 - he code you posted looks some how familiar.
Your next question would be to sort the text in the array into columns of Type codes 1 - 6?
I have been looking for a work around to it as the code is ambigous to look at as well.
Mark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|