locked
Value error in Class but works in VS 2010 RRS feed

  • Question

  • User801447716 posted

    Hi,

    I have ported an application from VS 2010 to VS 2014, one of my classes displays an error:

    'SitePageRedirection' is not a member of 'Site.TypeRedirection'

    The Class is:

    Public Class TypeRedirection
        Public Shared Function SitePageRedirection() As String
    
            Dim PType As String = HttpContext.Current.Session("PageType")
    
            'default return value
            Dim returnValue As String = "ApplicationSelectType.aspx"
    
            If PType = "Books" Then
                returnValue = "ApplicationSelectType1.aspx"
            ElseIf PType = "Cards" Then
                returnValue = "ApplicationSelectType2.aspx"
            End If
    
            Return returnValue
    
        End Function
    End Class

    and using this on my page:

                Response.Redirect(TypeRedirection.SitePageRedirection)
    


    Not sure what I am missing, any help is appreciated.

    Saturday, February 8, 2014 10:10 AM

Answers

  • User281315223 posted

    Do you have an actual instance of the TypeRedirection class in this case?

    'Create an instance of your TypeRedirection class'
    Dim typeRedirection As New TypeRedirection()
    
    'Access the property from that instance'
    Response.Redirect(typeRedirection.SitePageRedirection())

    Aside from that I can't really see anything that is going wrong and actually your current code should be working as expected as the following similar example works just fine :

    Public Sub Main()
    	Console.WriteLine(TypeRedirection.SitePageRedirection)
    End Sub
    	
    Public Class TypeRedirection
        Public Shared Function SitePageRedirection() As String
    		'Example to return'
    		Return "Example"
        End Function
    End Class
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 8, 2014 11:55 AM
  • User397347636 posted

    Yes - that's because VB allows accessing shared member via the type or an instance.  This is the thing I hate most about VB - it encourages coding practices (like accessing shared members via instances) which actually hinder an understanding of coding concepts.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 8, 2014 12:46 PM

All replies

  • User397347636 posted

    SitePageRedirection is a function, so you need to add an empty argument list:

    e.g.,

    Response.Redirect(TypeRedirection.SitePageRedirection())

    Forget this - in VB you can omit the empty argument list...

    Saturday, February 8, 2014 11:50 AM
  • User281315223 posted

    Do you have an actual instance of the TypeRedirection class in this case?

    'Create an instance of your TypeRedirection class'
    Dim typeRedirection As New TypeRedirection()
    
    'Access the property from that instance'
    Response.Redirect(typeRedirection.SitePageRedirection())

    Aside from that I can't really see anything that is going wrong and actually your current code should be working as expected as the following similar example works just fine :

    Public Sub Main()
    	Console.WriteLine(TypeRedirection.SitePageRedirection)
    End Sub
    	
    Public Class TypeRedirection
        Public Shared Function SitePageRedirection() As String
    		'Example to return'
    		Return "Example"
        End Function
    End Class
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 8, 2014 11:55 AM
  • User397347636 posted

    An instance is not required since the method is 'Shared'.

    The only other thing I can think of is that the call to SitePageRedirection is being made from C# - if that's the case then you need the empty argument list since C# is less forgiving than VB.

    Saturday, February 8, 2014 12:31 PM
  • User281315223 posted

    I noticed the Shared section after I had posted, however the original code appeared to execute just fine as seen in my example that was posted earlier. 

    Any additional code (such as the entire code-behind) would be helpful in determining exactly what might be going wrong.

    Saturday, February 8, 2014 12:39 PM
  • User397347636 posted

    Yes - that's because VB allows accessing shared member via the type or an instance.  This is the thing I hate most about VB - it encourages coding practices (like accessing shared members via instances) which actually hinder an understanding of coding concepts.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 8, 2014 12:46 PM