CR & Tab in VB 2005 Textbox

A

AWW

Using Textbox.Text = "123" & CStr(13) & "456"
I expect 2 lines on the screen but get 1 line with 13 in it.
It worked once in a RichTextBox but then stopped.
I just want to display aligned tabular data on the screen using CR &
Tabs to create data columns.
I am an old programmer but .Net novice.<g>
Help.
 
L

Lloyd Sheen

Using Textbox.Text = "123" & CStr(13) & "456"
I expect 2 lines on the screen but get 1 line with 13 in it.
It worked once in a RichTextBox but then stopped.
I just want to display aligned tabular data on the screen using CR &
Tabs to create data columns.
I am an old programmer but .Net novice.<g>
Help.

You may want to use the following constant under System.Environment

first is System.Environment.NewLine. This will ensure that you have the
correct setting for the newline character (no matter where it runs).

There is also a VBCRLF constant which can be used but is not really Dot.Net

Secondly (and gone if you use the above) the CStr is converting as you saw
to a string with that value. I can only suggest that you don't use any of
the old VB functions and go with straight Dot.Net. In the long run this
will make things easier and more consistant.

Lloyd Sheen
 
M

Michel Posseth [MCP]

First make sure the textbox`s multiline property is set to true

and maybe you would findit easier to use the handy VB contstants

VbCr ( cariage return )
VbCrlf ( cariage return linefeed )
VbTab ( tab )


regards

Michel
 
O

\(O\)enone

AWW said:
Using Textbox.Text = "123" & CStr(13) & "456"
I expect 2 lines on the screen but get 1 line with 13 in it.

I think the function you're looking for is Chr(), not CStr().

But anyway, you're much better off using vbCrLf instead:

\\\
Textbox.Text = "123" & vbCrLf & "456"
///
 
A

Armin Zingler

Using Textbox.Text = "123" & CStr(13) & "456"
I expect 2 lines on the screen but get 1 line with 13 in it. It
worked once in a RichTextBox but then stopped.
I just want to display aligned tabular data on the screen using CR &
Tabs to create data columns.
I am an old programmer but .Net novice.<g>
Help.


I guess you know that you wanted to write Chr(13) instead of CStr(13). :)

Or use vbCr instead.


Armin
 
M

Michel Posseth [MCP]

There is also a VBCRLF constant which can be used but is not really
Dot.Net

Secondly (and gone if you use the above) the CStr is converting as you saw
to a string with that value. I can only suggest that you don't use any of
the old VB functions and go with straight Dot.Net. In the long run this
will make things easier and more consistant.

Lloyd Sheen

Huh ???


Well read this

http://www.codeproject.com/useritems/novbruntimeref.asp

and read my responses

There is nothing old or outdated or whatever in the Microsoft Visual Basic
..NET Runtime

Just my thoughts regarding this mather

regards

Michel Posseth
 
L

Lloyd Sheen

Michel Posseth said:
Huh ???


Well read this

http://www.codeproject.com/useritems/novbruntimeref.asp

and read my responses

There is nothing old or outdated or whatever in the Microsoft Visual Basic
.NET Runtime

Just my thoughts regarding this mather

regards

Michel Posseth

Sorry what I meant was to keep the code Dot.Net you would use the functions
that are provide for each object. I do this since I use both VB and C# and
sometimes I need to use code (not enough for a seperate assembly) and if I
use the Dot.Net functions provided by the objects rather than the VB it is
easier to convert since it is mostly getting rid of ending semi colons and
changing square brackets into regular brackets (and the other stuff of
course).

I just find that this way (even though VB will not disappear , and I bought
a copy of VB1 in Long Beach the day it was first available so I have been
using VB for quite some time (I guess that was 91)).

Just my 2 cents

Lloyd Sheen
 
M

Michel Posseth [MCP]

Lloyd

Did you now that you can just set a reference to Microsoft.VisualBasic.dll
in a C# project and then use all the handy shortcuts in C# as well

And no you then not have a extra dependancy as we code on the framework and
the Microsoft.VisualBasic.dll is part of the framework


regards

Michel
 
A

AWW

Yes, multiline is True in both RichTextBox & TextBox and
both VbCr/VBTab work in RichTextBox but only VbTab in TextBox.
I can rewrite the whole box but would like to rewrite individual lines
and cannot find any way to set a position for the rewrite.
Thanks - so far.
 
O

\(O\)enone

Lloyd said:
Sorry what I meant was to keep the code Dot.Net you would use the
functions that are provide for each object. I do this since I use
both VB and C# and sometimes I need to use code (not enough for a
seperate assembly) and if I use the Dot.Net functions provided by the
objects rather than the VB it is easier to convert since it is mostly
getting rid of ending semi colons and changing square brackets into
regular brackets (and the other stuff of course).

There's nothing stopping you referencing Microsoft.VisualBasic.dll and using
the functions within it from C#, you know! :)
 
G

Guest

TextBox1.Text = String.Concat("hello", vbCr, "world") 'does not work
TextBox1.Text = String.Concat("hello", vbCrLf, "world") 'works
TextBox1.Text = String.Concat("hello", Environment.NewLine, "world") 'works
TextBox1.Text = String.Concat("hello", Chr(13), "world") 'doesn`t work
TextBox1.Text = String.Concat("hello", Chr(13), Chr(10), "world") 'works

in windows a newline is standard cariage return and linefeed


HTH

Michel
 
R

rowe_newsgroups

Yes, multiline is True in both RichTextBox & TextBox and
both VbCr/VBTab work in RichTextBox but only VbTab in TextBox.
I can rewrite the whole box but would like to rewrite individual lines
and cannot find any way to set a position for the rewrite.
Thanks - so far.





I can rewrite the whole box but would like to rewrite individual lines
and cannot find any way to set a position for the rewrite.

For the RichTextBox at least you have a Lines property and also a
SelectionStart and SelectionLength property you can use to quickly
modify a specific line or lines. I don't recall right now if the
standard TextBox exposes these members or not.

Thanks,

Seth Rowe
 
J

Joergen Bech

You may want to use the following constant under System.Environment

first is System.Environment.NewLine. This will ensure that you have the
correct setting for the newline character (no matter where it runs).

System.Environment.NewLine is hard-coded to return

ChrW(13) & ChrW(10)

I do not see how or where it would return anything else, unless there
are different versions of mscorlib out there.

Unless we are talking about a Unix implementation, in which case it
should return ChrW(13)
There is also a VBCRLF constant which can be used but is not really Dot.Net

Microsoft.VisualBasic.Constants.vbCrLf also returns ChrW(13) &
ChrW(10),
but is defined as a constant instead of a shared property like
System.Environment.NewLine.

Yes, a C# developer could reference Microsoft.VisualBasic to get
at vbCrLf, but why go to another assembly if you do not have to?

Regards,

Joergen Bech
 
A

AWW

Thanks - the vbLf does work in the Textbox and in the RichTextbox even
if not needed. Little things can be so annoying.<g>
 
M

Michel Posseth [MCP]

exactly the one i didn`t test :)




Thanks - the vbLf does work in the Textbox and in the RichTextbox even
if not needed. Little things can be so annoying.<g>

TextBox1.Text = String.Concat("hello", vbCr, "world") 'does not work
TextBox1.Text = String.Concat("hello", vbCrLf, "world") 'works
TextBox1.Text = String.Concat("hello", Environment.NewLine, "world")
'works
TextBox1.Text = String.Concat("hello", Chr(13), "world") 'doesn`t work
TextBox1.Text = String.Concat("hello", Chr(13), Chr(10), "world") 'works

in windows a newline is standard cariage return and linefeed


HTH

Michel



AWW said:
Yes, multiline is True in both RichTextBox & TextBox and
both VbCr/VBTab work in RichTextBox but only VbTab in TextBox.
I can rewrite the whole box but would like to rewrite individual lines
and cannot find any way to set a position for the rewrite.
Thanks - so far.

On Thu, 21 Jun 2007 20:38:04 +0200, "Michel Posseth [MCP]"


First make sure the textbox`s multiline property is set to true

and maybe you would findit easier to use the handy VB contstants

VbCr ( cariage return )
VbCrlf ( cariage return linefeed )
VbTab ( tab )


regards

Michel



<AWW> schreef in bericht
Using Textbox.Text = "123" & CStr(13) & "456"
I expect 2 lines on the screen but get 1 line with 13 in it.
It worked once in a RichTextBox but then stopped.
I just want to display aligned tabular data on the screen using CR &
Tabs to create data columns.
I am an old programmer but .Net novice.<g>
Help.
 
C

Cor Ligthert [MVP]

Michel,

Why are you showing this page, has it any more authority than the webpages
from Jaap from the Golden Cache?

If you are proofing something than please something from MSDN.

Cor
 
M

Michel Posseth [MCP]

Cor ,

No not because of any authority , but because of my comments on this mather
, i believe i reflect my opinion in more detail on this page ( see the
comments in "Why ?") i just didn`t like to type it all again , but pointed
to the page i commented on instead.

Michel
 
C

Cor Ligthert [MVP]

Michel,

I am not always happy what is written on that website.
Often very much the opinion from one man.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top