|
-
Feb 21st, 2000, 06:39 PM
#1
I have a search routine that finds matchs within a text file and records the location and file number into an array:
teststr = Input(LOF(3), #3)
location = InStr(1, teststr, searchstr, vbTextCompare)
loctot = loctot + location
If location > 0 Then
scount = scount + 1
ReDim Preserve arrsearch(0 To 1, 1 To scount)
arrsearch(0, scount) = b + 1 'disc number
arrsearch(1, scount) = loctot 'match location
GoTo jump
End If
It then loops and crops off the left of the string to the point of the match like this:
teststr = Right(teststr, Len(teststr) - (Len(Left(teststr, location - 1)) + Len(searchstr)))
I then have an array filled with match data. I compile a list out of this data and allow the user to choose which to display. I have to count the number of lines upto the 'location' value in the files so it can be exactly pin-pointed. The following code does this.
teststr = Input(LOF(3), #3)
teststr = Left(teststr, arrsearch(1, smatch) + Len(searchstr))
linecount = 0
Do Until 0 = InStr(1, teststr, Chr(13), vbTextCompare) Or 0 = InStr(1, teststr, Chr(10), vbTextCompare)
somit = InStr(1, teststr, Chr(10), vbTextCompare)
teststr = Right(teststr, Len(teststr) - somit)
linecount = linecount + 1
Loop
'smatch' is the position in the list of the match. The problem is that as we go down the list - 1st, 2nd, 3rd, 4th - and display each one the 'teststr' is cropped to one character less which as we reach the 6/7th match causes there to be fewer lines counted and thus an error.
Does anyone understand why this happens?
Does anyone understand what I'm on about?
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
|