3 Replies - 1199 Views - Last Post: 04 May 2010 - 12:24 PM Rate Topic: -----

#1 zbora23  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 57
  • Joined: 26-February 09

Reading lines in textbox

Posted 04 May 2010 - 11:30 AM

Hello,
I am doing my IT PROJECT (CV MAKER) at the moment in college and i have little bit problem with reding lines in txtbox.
     Dim lines() As String = TextBox4.Text.Split(Environment.NewLine)
        Try
            lines(0) = "                              -" & lines(0)
            lines(1) = "                              -" & lines(1)
            lines(2) = "                              -" & lines(2)
            lines(3) = "                              -" & lines(3)
            lines(4) = "                              -" & lines(4)
        Catch ex As Exception
            GoTo filan

        End Try




        

filan:

        MsgBox(lines(0) & vbNewLine & lines(1) & vbNewLine & lines(2) & vbNewLine & lines(3) & vbNewLine & lines(4))
 


What i want to do here is, read all lines in TextBox and assigne them to variables, as well as add somethig before them and stick all of them into one variable

for example if my text box will have 2 lines :

Hello
My Name is

"-" & line
"-" & line2

so it will look like

- Hello
- My Name is

and all of that in one variable

PS. this text box may have up to 15 -20 lines so i need some help for those numbers.

Is This A Good Question/Topic? 0
  • +

Replies To: Reading lines in textbox

#2 snikmotnairb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 70
  • Joined: 02-May 08

Re: Reading lines in textbox

Posted 04 May 2010 - 12:04 PM

This should do what you are asking.

     
Dim lines() As String = TextBox4.Text.Split(Environment.NewLine)
        
For myCount As Integer = 0 To lines.Length - 1

    lines(myCount) = "-" & lines(myCount).Trim

Next


Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Reading lines in textbox

Posted 04 May 2010 - 12:09 PM

Also note, the Textbox already has a built in string array of lines. So as long as the controls sees it as a line, you can just call its index
Example
MessageBox.Show(Textbox1.Lines(2)) will display the 3rd line in the textbox. No need to split them into your own array.
Was This Post Helpful? 1
  • +
  • -

#4 zbora23  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 57
  • Joined: 26-February 09

Re: Reading lines in textbox

Posted 04 May 2010 - 12:24 PM

View Postsnikmotnairb, on 04 May 2010 - 11:04 AM, said:

This should do what you are asking.

     
Dim lines() As String = TextBox4.Text.Split(Environment.NewLine)
        
For myCount As Integer = 0 To lines.Length - 1

    lines(myCount) = "-" & lines(myCount).Trim

Next



Great This code works perfectly for purposes i wanted, I really appreciate help.
Thanks snikmotnairb

PS. CharlieMay thanks for the tip for future

This post has been edited by zbora23: 04 May 2010 - 12:26 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1