Why doesn't this declaration work in my forms

Answered Why doesn't this declaration work in my forms

  • Saturday, May 07, 2005 7:25 AM
     
     

    Why doesn't this declaration work in my forms

    Imports microsoft.VisualBasic
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.IO
    Public Class ClassPrimary
        Friend s As String = ControlChars.CrLf

        Shared Sub main()
            Application.Run(New frmStartup)
        End Sub

    End Class

    When I type s in a form it is said to be undeclared.

    dennist

All Replies

  • Saturday, May 07, 2005 7:40 AM
    Moderator
     
     Answered
    Because in the above code, 's' is an instance method, and therefore can't be accessed without creating an instance of ClassPrimary.

    Put 'Shared' after Friend and then you should be able to do access it via 'ClassPrimary.s'.
  • Saturday, May 07, 2005 7:53 AM
     
     
    Thanks, but I don't think it's worth the trouble at this point.  Maybe for new variables where dim sChar as string = classprimary.s

    dennist