Hello all,

I would like to be able to find out what is in the textbox between the words QQQ1 and QQQ2, however I am not sure how to do this. The code I tried to do it with is...
VB Code:
  1. Public Sub TrimString(TheString As String, KeepAfter As String, KeepBefore As String)
  2. Dim posA As Long
  3. Dim posB As Long
  4. posA = 1
  5. posB = 1
  6. Dim incTill As Long
  7. incTill = Len(TheString) - Len(KeepAfter)
  8. Debug.Print incTill & " is intill"
  9. For i = 1 To incTill
  10. If Mid(TheString, posA, Len(KeepAfter)) = KeepAfter Then
  11. Debug.Print posA
  12. GoTo FoundKeepAfter
  13. posA = i
  14. End If
  15. Next
  16. TheString = "Cannot find KeepAfter"
  17. Exit Sub
  18. FoundKeepAfter:
  19. incTill = Len(TheString) - Len(KeepBefore)
  20. For j = 1 To incTill
  21. If Mid(TheString, posB, Len(KeepBefore)) = KeepBefore Then
  22. GoTo FoundKeepBefore
  23. posB = j
  24. End If
  25. Next
  26. TheString = "Cannot find KeepBefore"
  27. Exit Sub
  28. FoundKeepBefore:
  29. TheString = Mid(TheString, posA, posA - posB)
  30. DoEvents
  31. Text1.Text = TheString
  32. End Sub
  33.  
  34. Private Sub Command1_Click()
  35. TrimString Text1.Text, "QQ1", "QQQ2"
  36. End Sub
But it doesnt work Is there some good way to do it?

Thanks