Results 1 to 12 of 12

Thread: Copy VB.NET source code to C# projects

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    2

    Post Copy VB.NET source code to C# projects

    Looks like this tool helps you to convert any VB.NET class into C#. There's an online and offline version, which are both free!

    http://www.wimontheweb.com/ca_main.aspx

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Tried it on one of the most common things:

    MsgBox("Hello World")

    and it doesn't work.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Well duh. msgbox is a VB6 compatability thing. So they probably ignored it. MessageBox.Show is the "proper" .NET way.

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Junior Member
    Join Date
    Oct 2004
    Posts
    16
    but most of the books stated that Msgbox(text) is command for message box

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Originally posted by morpheus5
    but most of the books stated that Msgbox(text) is command for message box
    I guess that might be, but that's considered, well, almost depricated, or worse, inside of the VisualBasic namespace. MessageBox.Show() is "pure" .NET while MsgBox is well, certainly pure .NET, just happens it exists under the Microsoft and not System namespace.

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Have you guys seen most of the vb.net code that is out there? I see more vb people using msgbox than vb people that use MessageBox.Show...

    I see more of the Left, Right, CInt, CString, CLong, etc... than the Substring method, or the CType method.

    All of those are compaitibility, and are used quite often. If it doesn't do it right, then what is the point of trying to convert.

  7. #7
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    Great tool.. some code work.

    What's wrong with this simple line in VB.NET?

    VB Code:
    1. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    2.     Handles MyBase.Load
    3.  
    4.         Me.Text = "Version History"
    5.      
    6.     End Sub

    VB Code:
    1. using System;
    2.  
    3. // Handles MyBase.Load
    4. private void Form2_Load(System.Object sender, System.EventArgs e)
    5. {
    6.  
    7.     Me.Text = "Version History";
    8.  
    9. }

    Cheers,
    McoreD

  8. #8
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Indeed. What is wrong? Is this a test or are you getting a compile-time error?

  9. #9
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    I am sorry and nothing wrong with the VB.NET Code, it is the converted C#.NET Code which is wrong.

    The VB.NET code was converted to Me.Text = "Version History"; which is wrong in Visual C#.

  10. #10
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    oh, ok. "Me" in VB is the same thing as "this" in C#. So change "Me.Text" to "this.Text".

  11. #11
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    Originally posted by Mike Hildner
    oh, ok. "Me" in VB is the same thing as "this" in C#. So change "Me.Text" to "this.Text".
    thank you;

    My point was, the tool did conversions of far more advanced code:

    for example:

    VB Code:
    1. private string myGetText(string strName)
    2.         {
    3.  
    4.             try
    5.             {
    6.                 // get the current assembly
    7.                 System.Reflection.Assembly oAsm =
    8.                     System.Reflection.Assembly.GetExecutingAssembly();
    9.                 System.IO.Stream oStrm =
    10.                     oAsm.GetManifestResourceStream(oAsm.GetName().Name + "." + strName);
    11.                 // read contents of embedded file
    12.                 System.IO.StreamReader oRdr = new System.IO.StreamReader(oStrm);
    13.                 return oRdr.ReadToEnd();
    14.  
    15.             }
    16.             catch (Exception ex)
    17.             {
    18.                 throw ex;
    19.             }
    20.  
    21.         }

    But the tool failed to do simple VB.NET code like

    VB Code:
    1. Me.Text = "Version History"

    Cheers,
    McoreD

  12. #12
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Yeah, there's a few conversion tools out there, none of which are perfect. I've played with a couple of them, but really have found no need to convert to/from VB.NET from/to C#. Snippets are easy enough to do yourself, and complete classes can just be used as is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width