Results 1 to 5 of 5

Thread: Get Last Line Of text

  1. #1
    Hellstorm
    Guest

    Angry Get Last Line Of text

    Hey all dunno if this is possible but worth a try.

    Say I have a multiline textbox on my form Text1.Text and this is reading a chat room window all the time and putting the chat text in to that box. That ive done but can I put another textbox on the form say Text2.Text and in that goes the last line of text from Text1.Text?

    I dunno if that is clear enough but hopefully u get the jist of it.

    Please help!

  2. #2
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    VB Code:
    1. Private Sub Form_Load()
    2. Dim tempArr() As String
    3. 'Plug in some long string into text1
    4. Text1.Text = "I dont know what" & vbCrLf & "I am doing but I'm" & vbCrLf & " just going to keep blabbing" & vbCrLf & " on and on forever"
    5. 'Set up an array of strings and pass into it each substring
    6. 'seperated by the control return line feed character (vbcrlf)
    7. tempArr = Split(Text1.Text, vbCrLf)
    8. 'assign the last substring to the second textbox
    9. Text2.Text = tempArr(UBound(tempArr))
    10. End Sub

  3. #3
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    of course that will only work if you enter the text into the multiline textbox like this

    VB Code:
    1. text1.text = text1.text & "bla bla bla " & vbcrlf 'vbcrlf necessary for this to work

  4. #4
    Hellstorm
    Guest
    Thanks alot people but that only works if I type the text in which isnt what im doing. Is there a way to do exactly that but with text1.Text retreiving it from another window and not me typing it?

  5. #5
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Yeah, this code hasn't been tested cuz I'm at school but here goes...

    VB Code:
    1. Private Function GetLastLine(strString As String) As String
    2.     Dim i&, strLen&, c$, str$
    3.     strLen& = Len(strString$)
    4.  
    5.     For i& = strLen& To 0 Step -1
    6.         c$ = Mid$(strString$, i&, 1)
    7.         str$ = str$ & c$
    8.        
    9.         If c$ = Chr(13) Then
    10.             GetLastLine$ = str$
    11.             Exit Function
    12.         End If
    13.     Next i
    14. End Function
    Like I said, it might need some work, but you get the idea, right? It loops through each letter of the string from end to beginning and when it hits Chr(13), which is the enter key, it returns whatever it has run through and exits the function.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width