Line Feeds in VB
Sometimes it's the simple things that stump you. I'm converting somecode from C# to VB. What followed was a bit ofhead scratchingover what appeared to be the most trivial of tasks.
Take the following line and convert it to VB...
[C#]
System.Console.WriteLine("Hello\nWorld");
becomes...
[VB]
System.Console.WriteLine("Hello" & vbCrLf & "World")
or does it?
The VB code on my system produces "HelloWorld" rather than the two words on separate lines as expected.
Being a VB newbie, I have found the reason why to be twofold. Firstly, vbCrLf is not intrinsic to the language but rather defined as with other VB constants in the Microsoft.VisualBasic assembly. VS automagically imports the namespaces without telling anyone - the rest of us aren't so lucky. And secondly, because I am using a "scripting" product, explicit type checking is turned off by default - so vbCrLf is interpreted as an object rather than a constant.
The two combine to annoyingly require that users be instructed that they must explicitly import the Microsoft.VisualBasic namespace/s or take great care in the absence of explicit type checking.
Update: see here for another perspective on this issue... http://www.angrycoder.com/blog/entries/20030423.html