Results 1 to 5 of 5

Thread: Interfaces

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    448

    Interfaces

    I have the following code:

    Code:
    Imports System
    Imports System.Collections.Generic
    Imports System.Drawing
    Imports System.Linq
    Imports System.Windows.Forms
    Imports System.ComponentModel.Composition
    Imports System.ComponentModel.Composition.Hosting
    Imports Interfaces
    Imports System.Text
    
    Namespace DemoPlugInTwo
        <Export(GetType(IPlugins))> _
        Public Class DemoPlugInTwo
            Implements IPlugins
    
            Public Sub createControl(ByRef myPanel As Panel)
                Dim myButton As New Button()
                myButton.Text = "Click Me!"
                AddHandler myButton.Click, AddressOf myButton_Click
                myPanel.Controls.Add(myButton)
            End Sub
    
            Public Sub myButton_Click(ByVal sender As Object, ByVal e As EventArgs)
                MessageBox.Show("Hey Kevin")
            End Sub
    
            Public ReadOnly Property name() As String
                Get
                    Return "Demo Plugin Three"
                End Get
            End Property
    
            Public ReadOnly Property version() As String
                Get
                    Return "Version 5.0"
                End Get
            End Property
    
        End Class
    End Namespace
    but I am getting this error:

    Error 1 Class 'DemoPlugInTwo' must implement 'ReadOnly Property name() As String' for interface 'Interfaces.IPlugins'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers. C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\DemoPlugInThree\DemoPlugInThree\DemoPlugInThree.vb 14 20 DemoPlugInThree
    I am getting similiar errors for the other property and method. I have them set as read only. Any ideas?
    If I helped you please rate me.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Interfaces

    Just because you have members with those names doesn't mean that they implement the corresponding members from the interface. What you should ALWAYS do is hit <Enter> immediately after the "Implements SomeInterface" line and the IDE will add the skeleton code for you, including the "Implements" clause on each member. If you want to do it for yourself then you need to add the "Implements" clause yourself, e.g.
    vb.net Code:
    1. Public ReadOnly Property name() As String Implements IPlugins.name
    Also, while what you do is up to you it really makes no sense to me to not follow .NET coding conventions without very good reason. Those conventions dictate that property names start with an upper case character. Unless you have a good reason not to, you should follow that convention.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    448

    Re: Interfaces

    Thanks that worked perfectly. I am used to programming in c# but I was seeing if I could implement a plugin in visual basic. In c# you dont have to do that. I have a question for you though. In c# if I go to this line:

    Code:
    Public Class DemoPlugInTwo
            Implements IPlugins
    and hover over the IPlugins word and right click I can select implement interface. Is there a way to do that in vb?
    If I helped you please rate me.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Interfaces

    There is an equivalent in VB:
    hit <Enter> immediately after the "Implements SomeInterface" line
    In C# you have the choice of implementing or explicitly implementing. As far as I'm aware, VB doesn't support explicit implementation so there's no need for VB to wait for you to choose as there is in C#.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    New Member
    Join Date
    Aug 2009
    Posts
    1

    Unhappy Re: Interfaces

    Hi. I'm having the same error in spite of following the correct procedure and letting .NET automatically create for me the necessary skeleton of the interface property implementation in my code behind (i.e. I press Enter after the "Implements" line and .NET creates the code skeleton of the interface properties at the bottom of the class block). I found in microsoft that this was actually a bug in VS2005 and there was a fix given there (http://support.microsoft.com/kb/316581) but I don't think the fix can be applied to VS 2008.

    I can't fix the darn thing. I've tried the following actions with no success:
    1. I did a "Rebuild" on the project where my IView or interface and presenter were defined, then a rebuild on my Web site, then a rebuild on my whole solution.
    2. I tried to create a new IView and Presenter and then re-wired my code behind to consume these classes but ran into the same error.

    Any thoughts and possible resolution? I'm at my wits end.

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