Click here to Skip to main content
15,904,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys. i'm new in development.i'm trying to make a simple program that user input a text into textbox(form1). then when they click the button it will display in new form(form 2) that contains a few textboxs.text from textbox in form1 is separated into the textboxs in form2 by line. for example the first line of text in textbox(form 1) will display in textbox1(form2), second line will display in textbox2(form2) and so on. this is my code but output is error.


VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim form2 As New Form2
        form2.Show()

        Dim textreader As New System.IO.StreamReader(TextBox1.Text)
        Dim str1, str2, str3 As String
        str1 = textreader.ReadLine()
        str2 = textreader.ReadLine()
        str3 = textreader.ReadLine()
        'reader.Close()

        form2.TextBox1.Text = str1
        form2.TextBox2.Text = str2
        form2.TextBox3.Text = str3
    End Sub
Posted

For entering the text on multiple lines the MultiLine property of TextBox is to be set to True. When the MultiLine property is set to True, the Lines property of TextBox returns an array of lines entered in the TextBox. Using this property each line entered in the TextBox can be accessed and set in the TextBoxes of the Form2 as shown below

VB
'TextBox1.MultiLine = True

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim form2 As New Form2

    form2.TextBox1.Text = IF(TextBox1.Lines.Length >= 1,TextBox1.Lines(0),"") 
    form2.TextBox2.Text = IF(TextBox1.Lines.Length >= 2,TextBox1.Lines(1),"")
    form2.TextBox3.Text = IF(TextBox1.Lines.Length >= 3,TextBox1.Lines(2),"")

    form2.ShowDialog()
End Sub
 
Share this answer
 
v2
Comments
dinmail 13-May-12 20:17pm    
thanks..i try it. problem solved.
VJ Reddy 13-May-12 20:44pm    
You're welcome and thank you for the response.
Sounds like a multiline textbox used and each line of text to be broken down. Now, width of the textbox cannot determine a line as in code behind you will never have any idea about it. Assuming there would be a newline (enter) after every line, you can use that as a signal/flag to separate each line.

Look here on how to split based on newline: VB.NET split on new lines[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900