0

I have a publice variable (vrPassword) that is defined in a class. How to access its data across different projects in a solution?

I do not know if any re fences to this class needs to be given?

Thanks

Furqan Sehgal
  • 4,917
  • 33
  • 108
  • 167

1 Answers1

0

To improve the terminology, if it is defined in a class, then it is either a property or a field, not a variable - variable is always local. I would definitely recommend you using a public property bound to a private field, that's the correct OOP way to do it, so it should look like:

Private _vrPassword As String

Public Property vrPassword() As String
    Get
        Return _vrPassword
    End Get
    Set(value As String)
        _vrPassword = value
    End Set
End Property

(Note this is not the best practice of naming conventions, but you weren't asking about it.)

To use it from different project, you need to:

1) Reference the project or .dll file,

2) Add Imports Namespace.Of.The.Class to file from where you want to use it (in case the namespace is different)

3) If the variable is not static, you need to instantiate the class:

Dim classHoldingTheVariableInstance As New ClassHoldingTheVariable()
Dim password As String = classHoldingTheVariableInstance.vrPassword
Tomas Pastircak
  • 2,867
  • 16
  • 28