TextBox1.Lines(0)

  • Thread starter Thread starter I_AM_DON_AND_YOU?
  • Start date Start date
I

I_AM_DON_AND_YOU?

A simple query:

I have a textbox with multiline=true. Also there is a button1. In button1's
click the code written is

textbox1.lines(0) = "Microsoft"
textbox2.lines(1) = "Visual Basic"

Hope you understand what I am trying to achieve. In Textbox1, on line1 I
want to put "Microsoft" and on the second line I want to put "Visual Basic".
However, when I run this code it doesn't work (and raises an execption).

Could you please tell me what's wrong here............and what's the
alternative?

Thanks in advance!
 
This is in continuation of my previous post.

Now, if I change the code as:

TextBox1.Text = "Microsoft" & Chr(13)

TextBox1.Text = TextBox1.Text & "Visual Basic"

MsgBox(TextBox1.Lines(0))

MsgBox(TextBox1.Lines(1))

Now first message box shows "Microsoft" and second message box shows "Visual
Basic". This implies that "Micorsoft" is stored in Line0 and "Visual Basic"
is stored in Line1 of TextBox1.

However on the screen on TextBox1 it doesn't show them on separate line. In
fact both are separated by "|" character.
 
I_AM_DON_AND_YOU? said:
This is in continuation of my previous post.

Now, if I change the code as:

TextBox1.Text = "Microsoft" & Chr(13)

TextBox1.Text = TextBox1.Text & "Visual Basic"

MsgBox(TextBox1.Lines(0))

MsgBox(TextBox1.Lines(1))

Now first message box shows "Microsoft" and second message box shows
"Visual Basic". This implies that "Micorsoft" is stored in Line0 and
"Visual Basic" is stored in Line1 of TextBox1.

However on the screen on TextBox1 it doesn't show them on separate
line. In fact both are separated by "|" character.

Here, no "|" is displayed when I execute your code. I see
"MicrosoftVisualBasic". However, I get the same text in the two Msgboxes.

Why don't you type in two lines in the textbox and examine the separator?
Use

TextBox1.Text = "Microsoft" & vbCrLf & "Visual Basic"

or Environment.Newline.

BTW, if you intend to concatenate more strings, check out
System.Text.Stringbuilder.
 
* "I_AM_DON_AND_YOU? said:
Now, if I change the code as:

TextBox1.Text = "Microsoft" & Chr(13)

TextBox1.Text = TextBox1.Text & "Visual Basic"

MsgBox(TextBox1.Lines(0))

MsgBox(TextBox1.Lines(1))

Now first message box shows "Microsoft" and second message box shows "Visual
Basic". This implies that "Micorsoft" is stored in Line0 and "Visual Basic"
is stored in Line1 of TextBox1.

However on the screen on TextBox1 it doesn't show them on separate line. In
fact both are separated by "|" character.

You will have to use 'ControlChars.NewLine' or 'Environment.NewLine' to
separate the lines.
 
You can assign a new string() instance to the Lines property:

textbox1.Lines = new string() {"Microsoft", "Visual Basic"}

--
Johan Stenberg (MSFT), VB .NET Team
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "I_AM_DON_AND_YOU?" <[email protected]>
| Subject: TextBox1.Lines(0)
| Date: Sun, 19 Oct 2003 21:47:00 -0700
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: ppp-67-125-114-188.dialup.irvnca.pacbell.net
67.125.114.188
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148297
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| A simple query:
|
| I have a textbox with multiline=true. Also there is a button1. In
button1's
| click the code written is
|
| textbox1.lines(0) = "Microsoft"
| textbox2.lines(1) = "Visual Basic"
|
| Hope you understand what I am trying to achieve. In Textbox1, on line1 I
| want to put "Microsoft" and on the second line I want to put "Visual
Basic".
| However, when I run this code it doesn't work (and raises an execption).
|
| Could you please tell me what's wrong here............and what's the
| alternative?
|
| Thanks in advance!
|
|
|
 
Back
Top