Results 1 to 5 of 5

Thread: [RESOLVED] Writing RTB lines into textboxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Resolved [RESOLVED] Writing RTB lines into textboxes

    Here i am ..stuck again
    This time i have a RTB (look.text) that contains no more than 12 lines (it updates according to a listbox but it will never exceed 12 lines of text). The lines contain numbers like this:
    2345,0,0,1,36,... and the last line will always be a number like: + or -123456789
    I also have 12 textboxes (a0.text to a11.text).
    How do i write each line from the RTB in a textbox?-i can't show you my code because it looks stupid and no matter what i tried i always ended up getting the same error "Index was outside the bounds of the array"-

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Writing RTB lines into textboxes

    What do you mean by "write each line"? Just set the TextBox's Text property to that of the RichTextBox's Text property. Just make sure the TextBox's Multiline property is set to True.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Writing RTB lines into textboxes

    Let's say i have this in rtb:
    234,0,0,0
    123,3,5,6,7,3
    54,8,9,54
    354655

    I want each line to be written in a textbox:
    TextBox1.text = 234,0,0,0
    TextBox2.text = 123,3,5,6,7,3
    TextBox3.text = 54,8,9,54
    TextBox4.text = 354655

    Note: the rtb lines change according to combobox (it's combobox not listbox -my bad-) selection so they're not static values, they update every time the item selecteditem changes.

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Writing RTB lines into textboxes

    Since there are only 12 lines, does that mean you have 12 text boxes? If so, what you can do is access the Lines property of the RichTextBox. This will return an array of String objects. If there are 12 lines in the RichTextBox, then there will be 12 elements in the array.

    You can access these by indexing the array, starting at index 0 and going to index 11 ([Count Of Elements] - 1 = 12 - 1 = 11). All collections and arrays in .NET start at 0.

    So simply set the appropriate TextBox with the appropriate element indexed from the Lines property:
    Code:
    Dim lines = Me.RichTextBox1.Lines
    Me.TextBox1.Text = lines(0)
    '//etc...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Writing RTB lines into textboxes

    Damn it i have something similar. My mistake is that i wrote it like this:
    Me.TextBox1.Text = lines(1)
    ....
    Last line: Me.TextBox12.Text = lines(12)
    Probably that's where the error came from. I didn't know it starts from 0 and not from 1.
    I'll give it a try in a bit.

    Edit: it works now thank you. Can't believe i couldn't figure it out myself...
    Last edited by kid92; Aug 9th, 2011 at 11:59 AM.

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