locked
Question on C# to VB Conversion RRS feed

  • Question

  • User-748031297 posted

    VWD 2008 Express.  Visual Basic.

    I am converting some of the code from the SampleWebSite in the AJAX Controls Toolkit.  I converted the following C# code using an online coversion tool:

    using System;
    using System.Collections;
    using System.Web.UI;

    public partial class DefaultMaster_Default : MasterPage, IContentPlaceHolders
    {
        public IList GetContentPlaceHolders()
        {
            return ContentPlaceHolders;
        }
    }

    Which resulted in the following VB code:

    Imports System 
    Imports System.Collections 
    Imports System.Web.UI 
    
    Public Partial Class DefaultMaster_Default 
        Inherits MasterPage 
        Implements IContentPlaceHolders 
        Public Function GetContentPlaceHolders() As IList 
            Return ContentPlaceHolders 
        End Function 
    End Class 

    When I try to build the resulting page, I get the following error:

    Error 9 Class 'DefaultMaster_Default' must implement 'Function GetContentPlaceHolders() As System.Collections.IList' for interface 'IContentPlaceHolders' 

    Any idea what I need to do to fix this "error."  Thanks for the help.

    Wednesday, October 1, 2008 7:24 PM

Answers

  • User1439985827 posted

     I believe you need to add "Implements IContentPlaceHolders.GetContentPlaceHolders" after As IList of your function, like this: 

    Partial Public Class DefaultMaster_Default
    	Inherits MasterPage
    	Implements IContentPlaceHolders
    	Public Function GetContentPlaceHolders() As IList Implements IContentPlaceHolders.GetContentPlaceHolders
    		Return ContentPlaceHolders
    	End Function
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 1, 2008 7:37 PM
  • User397347636 posted

    The 'Implements' near the top just says that your class will implement the interface.

    In VB, the 'Implements' is also required on every method which satisfies the interface's requirements.  You are required to have a method implementing every method of the interface (an interface is like a contract), and VB requires that you explicitly state this for each method.  If you want you can use a different method name (unlike C#) since VB only looks at the 'Implements' clause for the method and verifies that the method parameters and return type matches the interface method.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 1, 2008 8:24 PM

All replies

  • User1439985827 posted

     I believe you need to add "Implements IContentPlaceHolders.GetContentPlaceHolders" after As IList of your function, like this: 

    Partial Public Class DefaultMaster_Default
    	Inherits MasterPage
    	Implements IContentPlaceHolders
    	Public Function GetContentPlaceHolders() As IList Implements IContentPlaceHolders.GetContentPlaceHolders
    		Return ContentPlaceHolders
    	End Function
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 1, 2008 7:37 PM
  • User-748031297 posted

    Thanks Kevin.  That seemed to do it.  Why are there now two "Implements" for IContentPlace Holders?  I am confused about just what "Implements" does?

    Wednesday, October 1, 2008 8:04 PM
  • User397347636 posted

    The 'Implements' near the top just says that your class will implement the interface.

    In VB, the 'Implements' is also required on every method which satisfies the interface's requirements.  You are required to have a method implementing every method of the interface (an interface is like a contract), and VB requires that you explicitly state this for each method.  If you want you can use a different method name (unlike C#) since VB only looks at the 'Implements' clause for the method and verifies that the method parameters and return type matches the interface method.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 1, 2008 8:24 PM
  • User1429898700 posted

     Hello!

     

    Which Conversion tool did you use to convert from C# to Classic Visual Basic?

    Any other free tools?

    Thanks!!

     

    minesh christian

     

     

    Thursday, October 16, 2008 11:37 AM
  • User-748031297 posted

    I used the free converter at:

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Thursday, October 16, 2008 11:44 AM
  • User1429898700 posted

    Thanks Doug!

    But I am looking for conversion to Classis VB (say VB 6) and not the VB.NET. Going bakwards!!

     

    Thursday, October 16, 2008 11:48 AM
  • User-748031297 posted

    Sorry I don't have a link for that.

    Thursday, October 16, 2008 11:50 AM