Results 1 to 7 of 7

Thread: Get rid of multiline textbox line if the line contains ONLY the date.

  1. #1

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    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.

  2. #2
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    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

  3. #3

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    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

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: Get rid of multiline textbox line if the line contains ONLY the date.

    Quote Originally Posted by ident View Post
    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.

  6. #6
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    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

  7. #7

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: Get rid of multiline textbox line if the line contains ONLY the date.

    Quote Originally Posted by Gruff View Post
    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
  •  



Click Here to Expand Forum to Full Width