This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to declare dictionary as Global Variable for reusing in scripts?

I would like to declare dictionary as global variable:

Dim Companies As Dictionary(Of String, String) = New Dictionary(Of String, String)
Companies.Add("CompanyA", "Comany A Desc")

When compile "Declaration expected." occurs

  • I assume you entered the code as is into a script which will lead to the error you are describing. Your code only work inside of a method as Google easily finds out by looking for the error message, but you didn't declare a function or procedure where your code resides.

    If you just need the global dictionary available in all your custom scripts, you could do the following in a script.

    Public Shared Companies As Dictionary(Of StringString= New Dictionary(Of StringStringFrom {
        {"CompanyA""Comany A Desc"},
        {"CompanyB""Comany B Desc"},
        {"CompanyC""Comany C Desc"}}

    This can be used in all script like in the following samples:

    Public Sub CCC_ScriptA()
        Dim c As String = Companies("CompanyA")
    End Sub
     
    Public Sub CCC_ScriptB()
        Dim c As String = Companies("CompanyB")
    End Sub

    HtH