---
title: "Accessibility"
canonical: "https://docs.cuesystem.com/space/CVCHELP/505610248/Accessibility"
format: markdown
---
> Macro (toc)

---

# Private

Private constants, variables, functions, and processes are accessible only from within the function/process/class/module in which it was declared. Private accessibility is used by default when no accessibility is specified.

#### Example: Followed declarations are equivalent

```visualbasic
Private Var VariableName As Long
Var VariableName As Long // private by default
```

Followed example shows the accessibility of a private module variable, a function, a function's variable, a class, and a class's variable. Modules Main and Second are placed in the same controller.

#### Module Main

```visualbasic
// module's variable, private by default
Var m As Long

// module's function, private by default
Function ModuleFunction()
  // function's variable, private by default
  Var f As Long
End Function

// class, private by default
Class CPrivateClass
  // class's variable, private by default
  Var c As Long

  // class's function, private by default
  Function ClassFunction()
  End Function
End Class

Private Process Autoexec()
  Var PrivateClass As CPrivateClass

  // module's private variable is accessible in the module
  m := 1
  
  // module's private function is accessible in the module
  ModuleFunction()

  // error, function's private variable is not accessible in the module
  // f := 1

  // error, class's private variable is not accessible in the module
  // PrivateClass.c := 1

  // error, class's private function is not accessible in the module
  // PrivateClass.ClassFunction()
End Process
```

#### Module Second

```visualbasic
Function Init()
  // error, Main module's private class is not accessible here
  // Var SecondClass As Main.CPrivateClass
  // error, Main module's private variable is not accessible here
  // Main.m := 1
  // error, Main module's private function is not accessible here
  // Main.ModuleFunction()
End Function
```

# Public

Public constants, variables, functions, and processes are accessible from all modules within a given controller.

The full path must be used when a constant, a variable, a function, and a process from another module are used. See the Structured identifier description.

Followed example shows the accessibility of a private module variable, a function, a function's variable, a class, and a class's variable. Modules Main and Second are placed in the same controller.

#### Module Main

```visualbasic
// module's variable
Public Var m As Long

// module's function
Public Function ModuleFunction()
  // error, public function variables are not allowed
  // Public Var f As Long
End Function

// class
Public Class CPublicClass
  // class's variable
  Public Var c As Long
  // class's function
  Public Function ClassFunction()
  End Function
End Class

Private Process Autoexec()
  Var PublicClass As CPublicClass
  
  // module's public variable is accessible in the module
  m := 1
  
  // module's public function is accessible in the module
  ModuleFunction()
  
  // class's public variable is accessible in the module
  // note: it is a good practice all class variables are private,
  // create public functions to operate them
  PublicClass.c := 1
  
  // class's public function is accessible in the module
  PublicClass.ClassFunction()
End Process
```

#### Module Second

```visualbasic
Function Init()
  // Main module's public class is accessible here
  Var AnotherClass As Main.CPublicClass
  
  // Main's module's public variable is accessible here
  Main.m := 1
  
  //Main module's public function is accessible here
  Main.ModuleFunction()
End Function
```

# Global

Global constants, variables, functions, and processes are accessible from across all modules and controllers in a given project.

Followed example shows the accessibility of a public and a global function. A controller TouchPanel1 contains modules Main and Second. A controller TouchPanel2 contains a module Main.

#### TouchPanel1.Main

```visualbasic
// TouchPanel1.Main's public function
Public Function PublicFunction()
End Function

// TouchPanel1.Main's global function
Global Function GlobalFunction()
End Function

Private Process Autoexec()
End Process
```

#### TouchPanel1.Second

```visualbasic
Function Init()
  // public function is accessible in the same controller
  Main.PublicFunction()
  // global function is accessible in the same controller
  Main.GlobalFunction()
End Function
```

#### TouchPanel2.Main

```visualbasic
Private Process Autoexec()
  // error, TouchPanel1.Main's public function
  // is not accessible in another controller
  // TouchPanel1.Main.PublicFunction()
  // TouchPanel1.Main's global function is accessible from across
  // all modules and controllers in a given project
  TouchPanel1.Main.GlobalFunction()
End Process
```

# Protected

The accessibility protected is used only within a class. Protected constants, variables, functions, and processes are accessible from within the class where they were declared and from within all classes which are inherited from this class.

#### Example

```visualbasic
Class CParent
  Protected Var x As Long
  
  Protected Function Clear()
    // protected variable x is accessible from within a class where it is declared
    x := 0
  End Function

  Function DoSomething()
    // protected function Clear is accessible from within a class where it is declared
    Clear()
  End Function
End Class


Class CChild Inherits CParent
  Protected Function SetTo10()
    // inherited protected variable x is accessible from within a child class
    x := 10
    // inherited protected function Clear is accessible from within a child class
    Clear()
  End Function
End Class

Private Process Autoexec()
  Var Parent As CParent
  Var Child As CChild

  // error, the protected variable is not accessible from outside a class
  // Parent.x := 1

  // error, the protected function is not accessible from outside a class
  // Parent.Clear()

  // error, the protected variable is not accessible from outside a class
  // Child.x := 1
End Process
```