Partager via


Globals.VariableExists[String] Property

Definition

Returns whether the specified variable exists.

public:
 property bool VariableExists[System::String ^] { bool get(System::String ^ Name); };
[System.Runtime.InteropServices.DispId(5)]
public bool VariableExists[string Name] { [System.Runtime.InteropServices.DispId(5)] get; }
[<System.Runtime.InteropServices.DispId(5)>]
[<get: System.Runtime.InteropServices.DispId(5)>]
member this.VariableExists(string) : bool
Public ReadOnly Property VariableExists(Name As String) As Boolean

Parameters

Name
String

Required. Represents the name of the variable.

Property Value

A Boolean value indicating true if the variable exists, false if it does not.

Attributes

Examples

Sub GlobalsExample(ByVal dte As DTE)  
    Dim globals As Globals  
    globals = dte.Solution.Globals  
    If globals.VariableExists("GlobalsExample") Then  
        ' The counter has already been set, so increment it.  
        Dim int32 As System.Int32  
        int32 = System.Int32.Parse(CStr(globals("GlobalsExample")))  
        int32 += 1  
        globals("GlobalsExample") = int32.ToString()  
    Else  
        ' Counter has never been set, so create and initialize it.  
        globals("GlobalsExample") = 1.ToString()  
        globals.VariablePersists("GlobalsExample") = True  
    End If  
    MsgBox("This variable has been called: " & _  
    globals.VariableValue("GlobalsExample") & " times.")  
End Sub  
void GlobalsExample(_DTE applicationObject)  
{  
    Globals globals;  
    globals = applicationObject.Solution.Globals;  
    if(globals.get_VariableExists("GlobalsExample"))  
    {  
        // The counter has already been set, so increment it.  
        System.Int32 int32;  
        int32 = System.Int32.Parse((string)  
        globals["GlobalsExample"]);  
        int32++;  
        globals["GlobalsExample"] = int32.ToString();  
    }  
    else  
    {  
        // Counter has never been set, so create and initialize it.  
        globals["GlobalsExample"] = 1.ToString();  
        globals.set_VariablePersists("GlobalsExample", true);  
    }  
    System.Windows.Forms.MessageBox.Show("This variable has been called:   
    " + globals.VariableValue["GlobalsExample"] + " times.");  
}  

Remarks

If you attempt to check the value of a variable with the VariableValue[] property and the variable does not exist, a new variable of that name is created with a null value. To distinguish between an empty variable and a nonexistent variable, use the VariableExists[] property.

Variables:

  • Have no limit as to length, other than system limitations.

  • Are case-insensitive.

  • Can contain any characters permitted by the system.

  • Are restricted to simple data types such as strings and numbers. No SafeArrays or IDispatch interfaces can be used.

Applies to