vbCrLf

  • Thread starter Thread starter Chris
  • Start date Start date
C

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
 
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.
 
Chris said:
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
 
Chris said:
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.
 
Josip Medved said:
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.
 
Use Environment.NewLine instead. If you wish, you can do
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?"
 
Josip Medved said:
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.
 
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.
 
Chris said:
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.
 
Back
Top