8 Replies - 401 Views - Last Post: 08 January 2013 - 12:40 PM Rate Topic: -----

#1 Knowledge needed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 07-January 13

Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 03:43 AM

I know how to get a specific line value of a txtbox
 TextBox1.Lines(1).ToString 
but i don't know how to use the value of
 TextBox1.Lines(1).ToString 
and "paste" it in example : the 2de line in txtbox5?

Please and thank you

Rudi
Is This A Good Question/Topic? 0
  • +

Replies To: Question - VB 08 XE How do I edit a specific line in a txtbox

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 04:37 AM

I am not really sure what you are try to achieve here but for copying and pasting have a look at this.

http://www.homeandle...t/nets4p10.html

To be able to use the value of a line in a text box you could simple do something like below

Dim lineOfText as string = TextBox1.Lines(1).ToString


then edit the variable to whatever you want
Was This Post Helpful? 0
  • +
  • -

#3 Knowledge needed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 07-January 13

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 05:32 AM

Thanks..But I like to use the value of
 Textbox1.Line(1).Tostring 
to edit the 5th line in textbox5.
I DON"T want to set textbox5.text = to the value.. I just want to edit that specific line.

I tried to use:

 Textbox1.Lines(4) = Textbox1.Line(1).Tostring 


but it didn't work

Please and Thank you

Rudi
Was This Post Helpful? 0
  • +
  • -

#4 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 06:07 AM

Hey i just through something together to see if i could get it work as i had never done what you are asking. what i done was just loop through each line of textbox 2 and then wrote and if statement to check if i was at the right line in textbox 2 and if i was get the value from text box 1 and insert it at that point in textbox 2.

Ps this is by no mean good code this is just a starting point for you good luck

       For Each i In txt2.Lines
            If i = 4 Then
                txt2.Text = txt1.Lines.GetValue(1).ToString
            End If
        Next

Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 06:12 AM

Try something like this...
        Dim tboxLines() As String
        tboxLines = TextBox1.Text.Split(CChar(vbNewLine))
        tboxLines(1) = "New text goes here."
        TextBox1.Text = Join(tboxLines, vbNewLine)


Was This Post Helpful? 0
  • +
  • -

#6 Knowledge needed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 07-January 13

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 09:55 AM

Sorry about my English, but I use Visual Basic Express Edition. I want to make the second line in textbox2 the value of textbox1.text

I just want to set a specific line in a textbox, and make it a specific value example
[code]
Dim a as string
a= "hi"
textbox2.lines(2) = a
[\code]

Sorry but didn't work for me :(
Was This Post Helpful? 0
  • +
  • -

#7 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 10:12 AM

Of course that didn't do it. We have given you a few ways to do it. Did you try them?

Here's what I suggested, in the form of a Function. It will work for any string that has multiple lines, that is, lines of text separated by end-of-line characters. All you need to do is to call the function, assigning the returned value to wherever you want it.
    Private Sub btnChange_Click(sender As System.Object, e As System.EventArgs) Handles btnChange.Click
        ' in this call, TxtBox1.Text is what we want to change
        ' 1, is the index of the line we want to change
        ' TextBox2.Lines(2).ToString is a line from another TextBox that we want to
        '  end up in TextBox1.Text

        TextBox1.Text = changeline(1, TextBox1.Text, TextBox2.Lines(2).ToString)
    End Sub

    Private Function changeline(ByVal whichline As Integer, ByVal oldtext As String, ByVal changetext As String) As String
        Dim tboxLines() As String
        tboxLines = oldtext.Split(CChar(vbNewLine))
        tboxLines(whichline) = changetext
        Return Join(tboxLines, vbNewLine)
    End Function


I don't know what more I can tell you, except that you will not get anywhere repeatedly trying something that doesn't work.
Was This Post Helpful? 0
  • +
  • -

#8 Knowledge needed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 07-January 13

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 07 January 2013 - 09:47 PM

!!!D.I.C Regular!!! - Thanks allot... works fine, I hope you can continue to share your knowledge with us newbies :D
I see that it takes the value of textbox2.line2 and make the value of textbox1.line2... :D
Was This Post Helpful? 0
  • +
  • -

#9 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Question - VB 08 XE How do I edit a specific line in a txtbox

Posted 08 January 2013 - 12:40 PM

View PostKnowledge needed, on 07 January 2013 - 10:47 PM, said:

!!!D.I.C Regular!!! - Thanks allot... works fine, I hope you can continue to share your knowledge with us newbies :D/>/>/>
I see that it takes the value of textbox2.line2 and make the value of textbox1.line2... :D/>/>/>

Yes it does, but only because it's called that way.

I wrote the call to the Function as:
TextBox1.Text = changeline(1, TextBox1.Text, TextBox2.Lines(2).ToString)


but it doesn't have to be a TextBox that gets changed, or a TextBox that supplies the string to substitute. For instance,

TextBox1.Text = changeline(5, TextBox1.Text, "This text will be placed in TextBox1, on the 6th line.")


or, assuming you've just read in a .txt file, contained in a variable called fileContents, and you want to change the 12th line to the current date and time...
fileContents = changeline(11, fileContents, Now())


So, basically any multiple-line variable may be changed with that Function, with any text from any source supplied as the new data.

Glad to be of assistance.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1