|
-
Feb 5th, 2002, 01:22 PM
#1
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!
-
Feb 5th, 2002, 01:35 PM
#2
Frenzied Member
VB Code:
Private Sub Form_Load()
Dim tempArr() As String
'Plug in some long string into text1
Text1.Text = "I dont know what" & vbCrLf & "I am doing but I'm" & vbCrLf & " just going to keep blabbing" & vbCrLf & " on and on forever"
'Set up an array of strings and pass into it each substring
'seperated by the control return line feed character (vbcrlf)
tempArr = Split(Text1.Text, vbCrLf)
'assign the last substring to the second textbox
Text2.Text = tempArr(UBound(tempArr))
End Sub
-
Feb 5th, 2002, 01:37 PM
#3
Frenzied Member
of course that will only work if you enter the text into the multiline textbox like this
VB Code:
text1.text = text1.text & "bla bla bla " & vbcrlf 'vbcrlf necessary for this to work
-
Feb 5th, 2002, 01:55 PM
#4
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?
-
Feb 5th, 2002, 03:18 PM
#5
Hyperactive Member
Yeah, this code hasn't been tested cuz I'm at school but here goes...
VB Code:
Private Function GetLastLine(strString As String) As String
Dim i&, strLen&, c$, str$
strLen& = Len(strString$)
For i& = strLen& To 0 Step -1
c$ = Mid$(strString$, i&, 1)
str$ = str$ & c$
If c$ = Chr(13) Then
GetLastLine$ = str$
Exit Function
End If
Next i
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|