none
Need Help Converting from C#.Net to VB.Net RRS feed

  • Question

  • Hi,

    I am developing a window based application and tried to convert and existing C#.NET source code to VB.NET. When I tried to convert the following code snippets from C#.NET to VB.NET using online tools , I am getting error. 

    Hope anyone can help me. And I really appreciate and thank you in advance.

     

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            public Dictionary<string, string> dict = new Dictionary<string,string>()

            {

                {"00020002", "UIMedia Storage SOP Class UID"}, 

                {"00020003", "UIMedia Storage SOP Inst UID"},

                {"00020010", "UITransfer Syntax UID"}

            };

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

     

    Malini

     

     

    Tuesday, January 31, 2012 5:06 AM

Answers

  • Hi malini,
             I observed there a different behaviour from converting code from c# to vb , due to anonymous type . Here you can have the below solution temporarily until I get back to you with the right solution.

    Public dict As New Dictionary(Of String, String)
        ' initialize in some method
        Private Sub SomeMethod()
            dict.Add("00020002", "UIMedia Storage SOP Class UID")
            dict.Add("00020003", "UIMedia Storage SOP Inst UID")
            dict.Add("00020010", "UITransfer Syntax UID")
        End Sub 
    

     


    If a post answers your question, please click Mark As Answer on that post and Mark as Helpful. Happy Coding...
    Tuesday, January 31, 2012 5:53 AM
  • I'm surprised that the online converters miss on this - this syntax has been around for a while:

    Public dict As New Dictionary(Of String, String)() From
    	{{"00020002", "UIMedia Storage SOP Class UID"},
    	{"00020003", "UIMedia Storage SOP Inst UID"},
    	{"00020010", "UITransfer Syntax UID"}}
    


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Proposed as answer by Murugan A Wednesday, February 1, 2012 6:09 AM
    • Marked as answer by Lie YouModerator Thursday, February 2, 2012 5:36 AM
    Tuesday, January 31, 2012 3:46 PM

All replies

  • Hi malini,

           Try this online converter. Its working

    http://converter.telerik.com/

     

    Your convertion to VB.

    Public dict As New Dictionary(Of String, String)() With { _
     {"00020002", "UIMedia Storage SOP Class UID"}, _
     {"00020003", "UIMedia Storage SOP Inst UID"}, _
     {"00020010", "UITransfer Syntax UID"} _
    }

     


    If a post answers your question, please click Mark As Answer on that post and Mark as Helpful. Happy Coding...
    Tuesday, January 31, 2012 5:23 AM
  • Hi Ragu,

    I tried your advice, still it is giving me the following error :

    Name of field or property being initialized in an object initializer must start with '.'

     

    Anyway thanks for coming forward to help me.

    Still finding for answer...

    Malini

     


    Tuesday, January 31, 2012 5:27 AM
  • Hi malini,
             I observed there a different behaviour from converting code from c# to vb , due to anonymous type . Here you can have the below solution temporarily until I get back to you with the right solution.

    Public dict As New Dictionary(Of String, String)
        ' initialize in some method
        Private Sub SomeMethod()
            dict.Add("00020002", "UIMedia Storage SOP Class UID")
            dict.Add("00020003", "UIMedia Storage SOP Inst UID")
            dict.Add("00020010", "UITransfer Syntax UID")
        End Sub 
    

     


    If a post answers your question, please click Mark As Answer on that post and Mark as Helpful. Happy Coding...
    Tuesday, January 31, 2012 5:53 AM
  • I'm surprised that the online converters miss on this - this syntax has been around for a while:

    Public dict As New Dictionary(Of String, String)() From
    	{{"00020002", "UIMedia Storage SOP Class UID"},
    	{"00020003", "UIMedia Storage SOP Inst UID"},
    	{"00020010", "UITransfer Syntax UID"}}
    


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Proposed as answer by Murugan A Wednesday, February 1, 2012 6:09 AM
    • Marked as answer by Lie YouModerator Thursday, February 2, 2012 5:36 AM
    Tuesday, January 31, 2012 3:46 PM
  • Thanks Ragu,

     

    I am using your temporary solution while I also looking for the correct solution.

     

    Malini

    Wednesday, February 1, 2012 3:44 PM
  • Hi malini,

                 Dave is correct . You can use that .


    If a post answers your question, please click Mark As Answer on that post and Mark as Helpful. Happy Coding...
    Thursday, February 2, 2012 6:09 AM
  • Dear All,

     

    Thansk for the helps extended.

     

    Malini

    Saturday, February 4, 2012 5:02 AM
  • Hello Malini,

                   This is Conversion from C# to VB.Net and this is totaly true.I have check the code into the system.

        Public dict As New Dictionary(Of String, String)
        ' initialize in some method
        Private Sub SomeMethod()
            dict.Add("00020002", "UIMedia Storage SOP Class UID")
            dict.Add("00020003", "UIMedia Storage SOP Inst UID")
            dict.Add("00020010", "UITransfer Syntax UID")
        End Sub
     
    ----------------------------------------------------------------

    Best Regards

    Thomas Waston


    Friday, February 10, 2012 5:43 AM