Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lines Of A Textbox

Status
Not open for further replies.

0CODE

Programmer
Feb 8, 2004
63
CA
The following code displays all the text in line 1 of the textbox:

msgbox(TextBox1.Lines(0))

now when i try to set / change in any way that line to different text it wont change for some reason (even properties like toupper don't work):

TextBox1.Lines(0) = StrReverse(TextBox1.Lines(0))

*any way to change a specific line the same way or im doing something wrong / another way to do this using the lines property* (doing string.replace does work but it does cause problems if there are identical lines ---> also you could also select the text and even identical lines wouldn't be a problem if you knew the position)

so basically my question is between the stars & any info on why the method i tried doesn't work would be appreciated.
_______
thanks
 
Have you tried playing with the .lines property? I've never noticed that property, but after playing with it, it's pretty clear that it is read only. It's purpose appears to solely be a read only string array of the current contents of the text box with each element of the array being a line of text. Take it for what it is and don't try to impute more functionality than what it demonstrates!
-Karl
 
i guessed it's read only too but the tool tip also mentions "sets" so it's either a mistake they made or something extra you need to do which i doubt. but the selecting text works ok for now.
 
Lines is not an indexed property. It returns an array of strings. The array is obviously a copy of the strings in the Textbox, not a reference to the array within the Textbox, otherwise a change to any elements would change the contents of the Textbox.

You should however be able to change an element by getting Lines, changing the elements and then setting Lines to the entire array.

Dim Lines() as string = TextBox1.Lines
Lines(0) = StrReverse(Lines(0))
TextBox1.Lines = Lines

I have seen this behavior with my own objects when I have a non-indexed property that returns a reference to a copy of an array, not a reference to the array itself.



Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top