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.
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
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
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.
Re: Get rid of multiline textbox line if the line contains ONLY the date.
Quote:
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.
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?
Re: Get rid of multiline textbox line if the line contains ONLY the date.
Quote:
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.