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

---

A variable stores a value. It is accessible by its name. A variable can be declared only within a module, a class, a function, or a process. A variable can be initialized by the expression that needn't be constant.

#### Syntax

```visualbasic
[Accessibility] Var Name[[ArrayItems]] As DataType[[TextItems]] [:= InitExpression] [Attribute]
```

#### Example of non-initialized variables

```visualbasic
Var DoorIsClosed As Boolean
Var Status As Byte
Var Index As Long
Var Temperature As Double
Var First As Char
Var RoomName As Text[100]
Var StartTime As Time
Var Temperatures[10] As Long
Var Names[10] As Text[50]
```

#### Example of initialized variables

```visualbasic
Var DoorIsClosed As Boolean := True
Var Status As Byte := 0
Var Index As Long := 600000
Var Temperature As Double := 20.5
Var First As Char := 'A'
Var RoomName As Text[100] := "Main hall"
Var StartTime As Time := #03/14/2009 12:35:05#

// all items of the array are initialized to 20
Var Temperatures[10] As Long := 20

// all items of the array are initialized to Text "Room"
Var Names[10] As Text[50] := "Room"
```

# _ClearVariable

This function set the variable to zero value.  The function is mainly suitable to set all items in a structure or array to zero value by calling one command.  

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> is set to **False**. Byte and Long are set to **0**. The double is set to **0.0**. ByteString is set to **&S""**. Text is set to **""**.  


> ⚠️ - controlCUE-one, controlCUE-two, touchCUE-5, touchCUE-5-B, signCUE-one - parameter variablename from another unit is supported since firmware 15.00q
> ⚠️ - Panels R01 - R09  - parameter variablename from another unit is supported since firmware 20.30j
> ⚠️ - Other kind of units - parameter variablename from another unit is supported since firmware 21.20

```visualbasic
Function _ClearVariable (Variablename)
```

#### Parameters 

Variablename 

It can be a variable of any type. 

#### Example without _ClearVariable 

```visualbasic
Structure Example 
  Var a As Text[20] 
  Var b As Long  
  Var c As Boolean 
  Var d As Double 
  Var e As ByteString[20] 
End Structure 

Var MyVar As Example 
Var MyArray[20] As Example 

Function SetMyVariablesToZero () 
  Var I As Long 

  MyVar.b := 0 
  MyVar.c := False 
  MyVar.d := 0.0 
  MyVar.e := &S"" 

  For I:=1 To 20 
    MyArray[i].a := "" 
    MyArray[i].b := 0 
    MyArray[i].c := False 
    MyArray[i].d := 0.0 
    MyArray[i].e := &S"" 
  End For 
End Function
```

#### The same example with using _ClearVariable 

```visualbasic
Structure Example 
  Var a As Text[20] 
  Var b As Long  
  Var c As Boolean 
  Var d As Double 
  Var e As ByteString[20] 
End Structure 

Var MyVar As Example 
Var MyArray[20] As Example 

Function SetMyVariablesToZero() 
  _ClearVariable(MyVar) 
  _ClearVariable(MyArray) 
End Function
```