Globals.VariableValue[String] 属性

定义

返回或设置具有指定名称的变量。

public:
 property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ VariableName); void set(System::String ^ VariableName, System::Object ^ value); };
[System.Runtime.InteropServices.DispId(0)]
public object this[string VariableName] { [System.Runtime.InteropServices.DispId(0)] get; [System.Runtime.InteropServices.DispId(0)] set; }
[<System.Runtime.InteropServices.DispId(0)>]
[<get: System.Runtime.InteropServices.DispId(0)>]
[<set: System.Runtime.InteropServices.DispId(0)>]
member this.VariableValue(string) : obj with get, set
Default Public Property VariableValue(VariableName As String) As Object

参数

VariableName
String

必需。 表示要检索的变量名的字符串。

属性值

Object

表示变量的对象。

属性

示例

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.");  
}  

注解

如果尝试检索不存在的变量,则将使用空值创建变量。 如果尝试设置的变量不存在,则将使用指定的值创建它。

备注

VariableValue[] 名称字符串不能包含空格、冒号 (: ) 或句点 ( ) 个字符。 如果名称包含任何这些字符,则会出现错误 "值不在预期范围内"。

适用于