Export (0) Print
Expand All

Globals Object

Visual Studio .NET 2003

The Globals object is a cache for storing data for the duration of each session of the Visual Studio environment, as well as across sessions using the VariablePersists property.

DTE

   Globals

[Visual Basic .NET]
Public Interface Globals
    Inherits IDispatch
[Visual Basic 6]
Class Globals
[C++]
interface Globals : IDispatch
[C#]
public interface Globals : IDispatch
[JScript .NET]
public interface Globals extends IDispatch

Remarks

The Globals object, for example, allows macros to have global variables whose values persist between executions. It can also be used to allow a command to implement a default value if it requires the user to enter information each time it executes, or to change its behavior after it has been invoked a certain number of times.

Data is stored in the Globals object as name/variant-value pairs. These name/value pairs can optionally be stored on disk using the VariablePersists property in order to maintain state between different sessions of Visual Studio.

Note   Variables containing objects or SafeArrays cannot be saved. If the value can be saved as a string, then it is saved in its native format.

Add-ins or macros can also use the Globals object to save user-defined data unique to each user between Visual Studio sessions. They can also use the Globals object to save and retrieve data to and from a solution (.sln) file.

Use the VariableValue property to save or read values saved with the Globals object.

Solutions.Globals

If you want to save data between sessions on a Solution basis, use DTE.Solution.Globals. The parent for Solutions.Globals is the Solution Object.

Data being written to Solutions.Globals must be convertible to a string. (You cannot, for example, store an object in the Solutions file.) You can, however, store a number since this can be represented as a string. When the values are reloaded, they will remain in string format.

DTE.Globals

When writing to DTE.Globals, except for objects and SafeArrays, there is no limitation on the type of data that can be saved. The length of a variable name, however, cannot exceed 31 characters.

The Parent property for DTE.Globals is the DTE object.

Project.Globals

Returns the object that holds values for an Add-in. Values are saved in the project file (.dsp, .vbp, and so forth). The values are saved any time the project writes its file.

Requirements

Namespace: EnvDTE

File: dte.olb

Example

Private objSoln As Solution

Public Property prop(ByVal somestuff As String)
   Get
      objSoln.Globals.VariableValue("SampleProp") = somestuff
      objSoln.Globals.VariablePersists("SampleProp") = True
   End Get
   Set(ByVal SampleProp)
      If Not objSoln.Globals.VariableExists("SampleProp") Then
         objSoln.Globals.VariableValue("SampleProp") = ""
         objSoln.Globals.VariablePersists("SampleProp") = True
      End If
      SampleProp = objSoln.Globals.VariableValue("SampleProp")
   End Set
End Property

See Also

Globals Object Properties, Events, and Methods

Show:
© 2014 Microsoft