Home All Groups Group Topic Archive Search About
Author
22 Sep 2006 1:19 PM
Chris
How can you in vb.net write vbCrLf to a file without using the
visualbasic namespace?

In C# you would just case 10/13 to char and right that.  I can't seem to
do that in vb.

Chris

Author
22 Sep 2006 1:26 PM
Josip Medved
> How can you in vb.net write vbCrLf to a file without using the
> visualbasic namespace?

> In C# you would just case 10/13 to char and right that.  I can't seem to
> do that in vb.

Use Environment.NewLine instead. If you wish, you can do
Convert.ToChar(number) thing also.

--
Greetings,
  Josip Medved,
  http://www.jmedved.com
Author
22 Sep 2006 1:43 PM
Herfried K. Wagner [MVP]
"Josip Medved" <jmed***@jmedved.com> schrieb:
>> How can you in vb.net write vbCrLf to a file without using the
>> visualbasic namespace?
>
>> In C# you would just case 10/13 to char and right that.  I can't seem to
>> do that in vb.
>
> Use Environment.NewLine instead. If you wish, you can do
> Convert.ToChar(number) thing also.

Both are not exactly the same as "\r\n" in C#.  'Environment.NewLine'
returns the system's new line character sequence, which may differ on
different operating systems.  Thus the compiler cannot perform certain
optimizations, which is not necessarily a disadvantage if the
platform-sensitivity of the new line character sequence is required.  I
would also use 'ChrW' instead of 'Convert.ToChar' because it will enable the
VB compiler to perform optimizations.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
22 Sep 2006 4:17 PM
Josip Medved
> > Use Environment.NewLine instead. If you wish, you can do
> > Convert.ToChar(number) thing also.

> would also use 'ChrW' instead of 'Convert.ToChar' because it will enable the
> VB compiler to perform optimizations.

ChrW is part of VisualBasic namespace if I remember correctly. Question
was
"How can you in vb.net write vbCrLf to a file without using the
visualbasic
namespace?"

--
Greetings,
  Josip Medved
  http://www.jmedved.com
Author
22 Sep 2006 4:22 PM
Herfried K. Wagner [MVP]
"Josip Medved" <jmed***@jmedved.com> schrieb:
>> > Use Environment.NewLine instead. If you wish, you can do
>> > Convert.ToChar(number) thing also.
>
>> would also use 'ChrW' instead of 'Convert.ToChar' because it will enable
>> the
>> VB compiler to perform optimizations.
>
> ChrW is part of VisualBasic namespace if I remember correctly. Question
> was
> "How can you in vb.net write vbCrLf to a file without using the
> visualbasic
> namespace?"

Yep, but why would you want to write code in VB without using features of VB
if those features are superior over the features provided by the .NET
Framework's class library?  I am questioning the OP's goal because it does
not make sense to me.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
22 Sep 2006 8:42 PM
Josip Medved
> Yep, but why would you want to write code in VB without using features of VB
> if those features are superior over the features provided by the .NET
> Framework's class library?  I am questioning the OP's goal because it does
> not make sense to me.

I have no idea why he wants to do that. :)
He just said that he wants it.

BTW. I would not say that it is superior. Just friendlier.

--
Greetings,
  Josip Medved
  http://www.jmedved.com
Author
22 Sep 2006 1:30 PM
Andrew Morton
Chris wrote:
> How can you in vb.net write vbCrLf to a file without using the
> visualbasic namespace?

Environment.NewLine might work for you (especially if you want it to change
when run in a different environment some time in the future).

> In C# you would just case 10/13 to char and right that.  I can't seem
> to do that in vb.

I suspect you meant 13/10 because CR=13 and LF=10.

Const CRLF As String = Chr(13) & Chr(10)

Andrew
Author
22 Sep 2006 1:32 PM
Herfried K. Wagner [MVP]
"Chris" <no@spam.com> schrieb:
> How can you in vb.net write vbCrLf to a file without using the visualbasic
> namespace?

Why would you want to use Visual Basic without actually using it?

'vbCrLf' or 'ControlChars.CrLf' are part of the Visual Basic Runtime
Library.  This library is always referenced in VB projects and the reference
cannot be removed for good reasons.

Instead of writing 'string s = "Hello\r\nWorld"' in C# you can write 'Dim s
As String = "Hello" & ControlChars.CrLf & "World"' in VB without any bad
implications on runtime performance.  The compiler will find out that
"Hello", 'ControlChars.CrLf', and "World" are constant string literals and
will emit the concatenated string to the binary when compiling.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
26 Sep 2006 9:06 AM
Phill W.
Chris wrote:
> How can you in vb.net write vbCrLf to a file without using the
> visualbasic namespace?

Lots of good answers from others but I'll chip this in anyway:

/Why/ do you want to do this?
The only reason I can think of is that you want to avoid any dependency
on Microsoft.VisualBasic.dll.  Well, if you're writing in Visual Basic,
you can't.  The Visual Basic compiler builds code that makes calls into
MS.VB and, if you go to the *tremendous* lengths required to avoid
these, what you wind up with won't look /anything/ like Basic (and will
probably run slower as well).

> In C# you would just case 10/13 to char and right that.  I can't seem to
> do that in vb.

AFAIK, you can't /cast/ an integer into a character, you have to
/convert/ it - C wraps this up in the same syntax for you; Visual Basic
doesn't.

Convert.ToChar

should get you close.

Or CChar, of course   ;-))

Regards,
    Phill  W.