C# to VB.NET

  • Thread starter Alhambra Eidos Kiquenet
  • Start date
A

Alhambra Eidos Kiquenet

Hi all,

always, I have developed with C#. Now, new project with VS 2005 + SQL
SERVER, and VB.NET like language.

Any help about vb.net ? For example, posters with VB.NET syntax, comparing
with C# syntax, etc

Code project sampe for VB.NET ??

thanks in advance...greetings
 
J

Joergen Bech

Conversion from C# to VB.Net is much easier than the other
way around, as C# is more "pure" and in some ways could
be considered a subset of VB.Net.

Or, before this devolves into a flame war, let me put it another
way: VB.Net programmers are likely to use elements from the
Microsoft.VisualBasic (and even Microsoft.VisualBasic.Compatibility)
namespaces. Translating such code to C# can be problematic
at times. C# developers are less like to use elements that cannot
be directly translated into their VB.Net equivalents.

There are plenty of articles comparing the two languages, e.g.
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
http://www.codeproject.com/KB/dotnet/vbnet_c__difference.aspx

Also check the external links section at the bottom of
http://en.wikipedia.org/wiki/Comparison_of_C_sharp_and_Visual_Basic_.NET

There are also free and commercial language conversion tools
which you can use to convert snippets - at least as a starting point,
e.g.
http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

In general, I do not recommend the use of such tools unless your
understanding of the target language is sufficient to spot the
deficiencies and issues in the translated code.

You might also benefit from comparing code in these samples,
which are available in C# and VB.Net versions:
http://msdn.microsoft.com/en-us/vs2005/aa718334.aspx

Regards,

Joergen Bech
 
M

Mathias Wührmann

Hi Joergen,

Joergen Bech said:
There are also free and commercial language conversion tools which
you can use to convert snippets - at least as a starting point, e.g.
http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
In general, I do not recommend the use of such tools unless your
understanding of the target language is sufficient to spot the
deficiencies and issues in the translated code.

ACK, this reminds me of my favorite post from
microsoft.public.de.german.entwickler.donet.vb newsgroup:

<original post, translated>
I need help in translating a line of C# code to VB.NET. The freely
available conversion tools yielded different results...

here is the code (num2 and num1 are of type int):
num2 = ((num2 << 5) + num2) ^ num1;

Results from the conversion tools:
num2 = CInt((num2 << 5 + num2) ^ num1)
num2 = (((num2 + 5) + num2) Or num1)
</original post>

<answer>
num2 = ((num2 << 5) + num2) ^ num1
</answer>

Do I need to say more? *g*


Regards,

Mathias Wuehrmann
 
J

Joergen Bech

Hi Joergen,



ACK, this reminds me of my favorite post from
microsoft.public.de.german.entwickler.donet.vb newsgroup:

<original post, translated>
I need help in translating a line of C# code to VB.NET. The freely
available conversion tools yielded different results...

here is the code (num2 and num1 are of type int):
num2 = ((num2 << 5) + num2) ^ num1;

Results from the conversion tools:
num2 = CInt((num2 << 5 + num2) ^ num1)
num2 = (((num2 + 5) + num2) Or num1)
</original post>

<answer>
num2 = ((num2 << 5) + num2) ^ num1
</answer>

Do I need to say more? *g*


Regards,

Mathias Wuehrmann

That's pretty funny.

And if you paste the same code into the converter I
linked to (or http://converter.telerik.com/), we get

num2 = ((num2 << 5) + num2) Xor num1

If we grab another one at
http://www.kamalpatel.net/ConvertCSharp2VB.aspx

we get

num2 = ((num2 < 5) + num2) ^ num1

Yes, only one "<" instead of "<<" and "Xor" instead of "^".

Actually, I believe the first conversion to be the correct one -
not the one you provided. As far as I am able to read the online
documentation, the "^" character in C# means logical XOR,
whereas the same character in VB.Net means "raises a number
to the power of another number". (Please correct me if I am wrong).

Only proves my point that one needs to be able to evaluate
the output - which kind of obviates the need for such converters.

Occasionally I write something in one language, compile it, and
then use Reflector to decompile it to another language, just to see
what it looks like. That approach has its own pitfalls.
I wonder if Reflector still chokes when attempting to decompile a
function that uses On Error Resume Next? :) Haven't tried that one
for a long time.

Regards,

Joergen Bech
 
J

Joergen Bech

On Wed, 21 May 2008 12:32:35 +0200, Mathias Wührmann

we get

num2 = ((num2 < 5) + num2) ^ num1

Yes, only one "<" instead of "<<" and "Xor" instead of "^".

---snip---

Make that: and "^" instead of "Xor".

Now I cannot even read what I am writing myself :(

/JB
 
D

David Anton

Ack - you have to have some idea of what is correct before you knock the
tools - your 'correct' answer is wrong - the answer is (via Instant VB):
num2 = ((num2 << 5) + num2) Xor num1

Also, be aware than many of the online tools were done as a 'one-off' and
are not maintained - but they are still available, giving all the converters
a bad name. You can easily figure out which ones fit this description.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
 
M

Mathias Wührmann

Hi David,

David said:
Ack - you have to have some idea of what is correct before you knock
the tools - your 'correct' answer is wrong - the answer is (via
Instant VB): num2 = ((num2 << 5) + num2) Xor num1

thanks for getting this right. As you can see, my knowledge in C# is
very limited either, so I wasn't aware of the differences of '^' in C#
and VB.NET. ;-)

Regards,

Mathias Wuehrmann
 

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