Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Warning function 'productname' conflicts frm_orderform_A155751 with property 'productname' in the base class 'Control' and should be declared 'Shadows'.

What I have tried:

VB
Private Function productname() As String
        Dim lastid As String = run_sql_query("SELECT MAX(FLD_PRODUCT_NAME) AS LASTID FROM TBL_PRODUCT_A155751").Rows(0).Item("LASTID")

        Dim newid As String = Mid(lastid, 2) + 1

        Return newid
    End Function
Posted
Updated 6-Dec-16 18:09pm
v3

1 solution

The warning is quite informative, you have a property and a function that both use the same name and therefore cause ambiguity. Consider the following example which causes the same warning
VB
Public Class BaseClass
    Public Property SomeFunctionality As String
        Get
            Return ""
        End Get
        Set(value As String)

        End Set
    End Property
End Class

Public Class InheritedClass
    Inherits BaseClass

    Public Function SomeFunctionality() As String
       'This function uses the same name as the underlying property
    End Function
End Class

One way to remove the warning is to define the shadows (which is actually automatically defined for you in this case). For example
VB
Public Class InheritedClass
    Inherits BaseClass

    Public Shadows Function SomeFunctionality() As String

    End Function
End Class

But in my opinion the correct solution would be to use different names. If you define the Shadows keyword you deliberately hide functionality and that's not probably what you want in the end.

So the fixed code should look like
VB
Public Class BaseClass
    Public Property SomeFunctionality As String
        Get
            Return ""
        End Get
        Set(value As String)

        End Set
    End Property
End Class

Public Class InheritedClass
    Inherits BaseClass

    Public Function AnotherFunctionality() As String
       ' Now the name is different so no ambiguity in calling anymore
    End Function
End Class


For more information, have a look at
- Default property '<propertyname1>' conflicts with default property '<propertyname2>' in '<classname>' and so should be declared 'Shadows'[^]
- Shadows (Visual Basic)[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900