-
May 17th, 2014, 12:37 PM
#1
Thread Starter
Member
Get rid of multiline textbox line if the line contains ONLY the date.
I am working on something that adds lines to a multiline textbox using a timer with specific variables. The start of each line has the date (Datetime.Now). Sometimes the lines ONLY have the date and I need them to be deleted. All of the other lines have the date and some other stuff. Sorry for the horrible description....I need the line with the date only to be deleted without the lines with everything on them having the date deleted from them also. Thanks.
-
May 17th, 2014, 01:35 PM
#2
Re: Get rid of multiline textbox line if the line contains ONLY the date.
If you are writing the code that adds the lines then the correct answer is to test for an empty line and do not add the line to the textbox if it is empty. This is much more efficient than cleaning up after the fact.
Code:
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
'Something in your code retrieves the variables a,b, and c
Dim FreshLine As String = (a & b & c).Trim
If FreshLine <> "" Then
TextBox1.Text &= DateTime.Now & " " & FreshLine & Environment.NewLine
End If
End Sub
Burn the land and boil the sea
You can't take the sky from me
~T
-
May 17th, 2014, 04:06 PM
#3
Thread Starter
Member
Re: Get rid of multiline textbox line if the line contains ONLY the date.
Thanks for the help. The line above causes my textbox to be spammed though. I believe the trim function works but I am not sure how to set it up to delete JUST blank lanes that only have the date and nothing else.
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim timeStamp As DateTime = DateTime.Now
TextBox1.Text = Replace(TextBox1.Text, vbLf & vbCr, "")
If LastCheckedForegroundTitle = "" OrElse Not LastCheckedForegroundTitle = GetActiveWindowTitle() Then
LastCheckedForegroundTitle = GetActiveWindowTitle()
TextBox1.Text &= Environment.NewLine & timeStamp & ": " & (LastCheckedForegroundTitle & vbCrLf)
End If
Dim FreshLine As String = LastCheckedForegroundTitle.Trim
If FreshLine <> "" Then
TextBox1.Text &= DateTime.Now & " " & FreshLine & Environment.NewLine
End If
End Sub
This is what I am workin with. Maybe this will help you help me :P
-
May 17th, 2014, 06:13 PM
#4
Re: Get rid of multiline textbox line if the line contains ONLY the date.
Why would you add a line to delete? Check agasint what ever your adding first.
-
May 17th, 2014, 09:07 PM
#5
Thread Starter
Member
Re: Get rid of multiline textbox line if the line contains ONLY the date.
Originally Posted by ident
Why would you add a line to delete? Check agasint what ever your adding first.
Hey man, I don't understand. Why comment on a post that you feel the need to slaughter the creator of. This forum was made for people to get help, was it not? What you have told me has a very negative attitude. Please keep it to your self.
-
May 17th, 2014, 11:38 PM
#6
Re: Get rid of multiline textbox line if the line contains ONLY the date.
pancakesplatter,
It is apparent you do not understand your own code.
Simply cutting and pasting my code at the bottom will not make your code work.
What I posted was just an example of how to skip adding an empty line.
You are going to have to alter your code to make it do something similar.
I suggest you re-read your code carefully and try to understand how it functions.
BTW ident simply restated what I said originally. Why should that bother you?
Last edited by Gruff; May 17th, 2014 at 11:41 PM.
Burn the land and boil the sea
You can't take the sky from me
~T
-
May 18th, 2014, 01:34 AM
#7
Thread Starter
Member
Re: Get rid of multiline textbox line if the line contains ONLY the date.
Originally Posted by Gruff
pancakesplatter,
It is apparent you do not understand your own code.
Simply cutting and pasting my code at the bottom will not make your code work.
What I posted was just an example of how to skip adding an empty line.
You are going to have to alter your code to make it do something similar.
I suggest you re-read your code carefully and try to understand how it functions.
BTW ident simply restated what I said originally. Why should that bother you?
Ok man, thanks for the help. In the end what you provided me with didn't help me at all. I guess I should have provided a piece of the code that I was asking for help with to begin with, so this was all my own fault. Sorry for the confusion and dull explanations.
Last edited by pancakesplatter; May 18th, 2014 at 01:42 AM.
Tags for this Thread
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
|