i was trying to figure out this code by myself today and took me a bit before getting to this point

vb Code:
  1. Private Function GetWord(TextBox_Name As TextBox) As String
  2. Dim WordFound As String
  3. Dim SplitWords() As String
  4. Dim WordFoundSplit() As String
  5. Dim DefaultStartPOS As Long
  6. Dim StartPOS As Long
  7. Dim WordPOS As Long
  8. Dim EndPOS As Long
  9. Dim i As Integer
  10.  
  11. On Error Resume Next
  12.  
  13. WordFound = ""
  14. StartPOS = 0
  15. EndPOS = 0
  16. WordPOS = 0
  17.  
  18. DefaultStartPOS = TextBox_Name.SelStart
  19. SplitWords = Split(TextBox_Name, Chr(32))
  20.  
  21. If DefaultStartPOS <= Len(SplitWords(0)) Then
  22.    TextBox_Name.SelStart = 0
  23.    TextBox_Name.SelLength = Len(SplitWords(0))
  24.    WordFound = TextBox_Name.SelText
  25.    TextBox_Name.SelLength = 0
  26.    TextBox_Name.SelStart = DefaultStartPOS
  27.    Me.Caption = WordFound
  28. Else
  29.    WordPOS = Len(SplitWords(0))
  30.    
  31.    For i = 1 To UBound(SplitWords)
  32.       StartPOS = WordPOS
  33.       WordPOS = WordPOS + Len(SplitWords(i)) + 1
  34.       EndPOS = WordPOS
  35.    
  36.       If DefaultStartPOS <= EndPOS And DefaultStartPOS > StartPOS Then
  37.          TextBox_Name.SelStart = WordPOS - Len(SplitWords(i))
  38.          TextBox_Name.SelLength = Len(SplitWords(i))
  39.          WordFound = TextBox_Name.SelText
  40.          TextBox_Name.SelLength = 0
  41.          TextBox_Name.SelStart = DefaultStartPOS
  42.          WordFoundSplit = Split(WordFound, vbNewLine)
  43.          WordFound = WordFoundSplit(0)
  44.          Exit For
  45.       End If
  46.    Next
  47. End If
  48.  
  49. GetWord = WordFound
  50. End Function
  51.  
  52. Private Sub txtScript_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  53. lblWord.Caption = GetWord(txtScript)
  54. End Sub


is there a easier formula or easier way to find the word you click on in a textbox(multiline)?