Results 1 to 4 of 4

Thread: need help!

  1. #1
    Member
    Join Date
    Oct 10
    Posts
    39

    need help!

    how to remove the first line of textbox and add it to other textbox?

  2. #2
    Fanatic Member
    Join Date
    Dec 07
    Location
    Albacete, españa
    Posts
    578

    Re: need help!

    Code:
            TextBox2.Text = TextBox1.Lines(0) 'copied the first line
            Dim b As String() = Split(TextBox1.Text, vbNewLine), splits the text into lines
            TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 2) ' joins them together again, ignoring the first line
    A fun card game written in VBA within Excel Tri Peaks

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,748

    Re: need help!

    First of all, everyone who posts a question here needs help, so your thread title is all but useless. The title is supposed to help us determine which threads are relevant to us without having to waste our time opening every single one. Sometimes, if the title doesn't tell me anything then I just ignore the thread. Do you want people ignoring your thread? Please provide a title that describes the topic of the thread.

    As for the question, you should work with the Lines property of the TextBox, which allows you to get or set the contents of the control as a String array containing one element per line. You can get the Lines property and get the first line from the first element. You can then copy all but the first line to a new array, which can be done in several ways. One way would be to create a List(Of String) from the array, Remove the first item and then create a new array from the List. You can then assign the new array back to the Lines property. As for adding the line to another TextBox, you could use the AppendText method or just the concatenation operator (&), or you could work with the Lines property again.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,461

    Re: need help!

    vb.net Code:
    1. Dim transfer As String = TextBox1.Lines(0)
    2.         TextBox1.Text = TextBox1.Text.Substring(transfer.Length + 1)
    3.  
    4.         TextBox2.AppendText(vbCrLf & transfer) 'adds at end
    5.  
    6. '------- OR -------
    7.  
    8.         TextBox2.Text = transfer & vbCrLf & TextBox2.Text 'adds at start
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

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