xcannon
10-13-2005, 03:28 PM
I made this function, and 50% of the time when I go to use it, it freezes up. My goal was to make a funcion that gets EVERYTHING between two strings. Here it is:
Public Function GrabItems(ByVal strSource As String, ByVal strStart As String, ByVal strEnd As String, ByVal listAdd As Object) As Boolean
Dim lnCurrentPos As Long
Dim lnTextStart As Long
Dim lnTextEnd As Long
Dim bolContinue As Boolean
Dim strFound As String
bolContinue = True
lnCurrentPos = InStr(1, strSource, strStart, vbTextCompare)
If lnCurrentPos > 0 Then
Do Until bolContinue = False
lnTextStart = lnCurrentPos + Len(strStart)
lnTextEnd = InStr(lnTextStart, strSource, strEnd, vbTextCompare)
If lnTextEnd > 0 And lnTextEnd > lnTextStart Then
strFound = Mid(strSource, lnTextStart, lnTextEnd - lnTextStart)
listAdd.AddItem strFound
lnCurrentPos = InStr(lnTextEnd + Len(strEnd), strSource, strStart, vbTextCompare)
If lnCurrentPos < lnTextStart Then
bolContinue = False
End If
Else
bolContinue = False
End If
Loop
End If
End Function
Public Function GrabItems(ByVal strSource As String, ByVal strStart As String, ByVal strEnd As String, ByVal listAdd As Object) As Boolean
Dim lnCurrentPos As Long
Dim lnTextStart As Long
Dim lnTextEnd As Long
Dim bolContinue As Boolean
Dim strFound As String
bolContinue = True
lnCurrentPos = InStr(1, strSource, strStart, vbTextCompare)
If lnCurrentPos > 0 Then
Do Until bolContinue = False
lnTextStart = lnCurrentPos + Len(strStart)
lnTextEnd = InStr(lnTextStart, strSource, strEnd, vbTextCompare)
If lnTextEnd > 0 And lnTextEnd > lnTextStart Then
strFound = Mid(strSource, lnTextStart, lnTextEnd - lnTextStart)
listAdd.AddItem strFound
lnCurrentPos = InStr(lnTextEnd + Len(strEnd), strSource, strStart, vbTextCompare)
If lnCurrentPos < lnTextStart Then
bolContinue = False
End If
Else
bolContinue = False
End If
Loop
End If
End Function