[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"-
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.
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.
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...
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...