Keyword

Global


Description

Identifies the Global scope, making it possible to refer to items that might otherwise be ambiguous.

Usage

Global.identifier

Notes

Global works similarly to Self, Me and Super and is most useful when working with namespaces. You use it to refer to a Global identifier (such as a module or namespace) that might otherwise be inaccessible because they are hidden by local identifiers (i.e. methods or variables) in the current scope.

When using Global, assigning values to properties is not supported.

Sample code

In this example, there is a module named Utility and another named AppInfo. Inside AppInfo there is a variable also named Utility. Code written in any method of the AppInfo module would assume implicitly that Utility refers to the local variable rather than the module. By adding the Global keyword prefix, you are being explicit that you mean the module rather than the local variable:

Module Utility
  Protected Version As Integer
End Module

Module AppInfo
  Protected Version As String

  Protected Sub GetAppInfo()
    ' Get the value of Utility.Version and assign it to our local Version
    Version = Utility.Version.ToString

    ' But now we have a local variable named utility, which shadows module Utility!
    Var utility As Color

    ' In order to reach the Utility.Version, we must explicitly back out to the global scope
    Global.Utility.Version = utility.Hue.ToInteger

    ' The first assignment can also be rephrased like this:
    Global.AppInfo.Version = Global.Utility.Version.ToString
  End Sub
End Module

Compatibility

All project types on all supported operating systems.