---
title: "Programming module"
canonical: "https://docs.cuesystem.com/space/CVCHELP/509083842/Programming%20module"
format: markdown
---
> Macro (toc)

---

The program code is placed in one module or it can be distributed to more modules. The module contains a program code of data types, constants, variables, properties, functions, processes, and comments. 

The module named Main is created automatically. It is the default module. The user can create other modules. 

Note: The program code can be placed in the project resources as well. The project resources contain the source code, pictures, fonts, texts, animations, sounds, or data and documentation. 

#### Complex example of a module 

```visualbasic
// -------------------------------------------------------------- 
// data types 
// -------------------------------------------------------------- 

// enum data type 
Enum BASIC_COLOURS 
  White, 
  Black, 
  Red, 
  Green, 
  Blue, 
  Yellow 
End Enum 

Structure ROOM 
  Var Length As Long 
  Var Width As Long 
  Var Height As Long 
End Structure 

// class data type 
Class CPosition 
  Var X As Long // CPosition's variable 
  Var Y As Long // CPosition's variable 
  // CPosition's public function 
  Public Function GetX() As Long 
    Return Value X 
  End Function 
End Class 

// class data type 
Class CPoint Inherits CPosition 
  Var Colour As Long // CPoint's variable 
  // CPoint's public function 
  Public Function SetColour(NewColour As Long) 
    Colour := NewColour 
  End Function 

  // CPoint's public function 
  Public Function GetColour(NewColour As Long) As Long 
    Return Value Colour 
  End Function 
End Class 
 
// -------------------------------------------------------------- 
// constants 
// -------------------------------------------------------------- 

Const MINIMUM_TEMPERATURE As Double := 0.0 
Const MAXIMUM_TEMPERATURE As Double := 30.0 
Const PI As Double := 3.1415926535 
Const START_TIME As Time := #03/14/2009 12:35:05# 
 
// -------------------------------------------------------------- 
// variables 
// -------------------------------------------------------------- 

Var RoomName As Text[100] := "Main hall" 
Var RoomColour As BASIC_COLOURS := BASIC_COLOURS.White 
Var DoorIsClosed As Boolean := True 
 
// -------------------------------------------------------------- 
// properties 
// -------------------------------------------------------------- 

Public Property PushButtonColor As Long WithAttributes 
{
  DisplayName := "Button color", 
  EditMode := "Color", 
  PropertyGroup := "Color setting" 
} 
 
// -------------------------------------------------------------- 
// functions 
// -------------------------------------------------------------- 

Function GetTemperatureMessage(Temperature As Double, ByRef Message As Text) 
  If Temperature < MINIMUM_TEMPERATURE Then 
    Message := "Increase temperature" 
  Else 
    Message := "Temperature is OK" 
  End If 
End Function 

Function GetAverageTemperature(Temp1 As Double, Temp2 As Double) As Double 
  Return Value (Temp1 + Temp2) / 2 
End Function 
 
// -------------------------------------------------------------- 
// processes 
// -------------------------------------------------------------- 

Process CheckInputs(MaxValue As Long) 
  // check it 
End Process 

Private Process Autoexec() 
  // local variables 
  Var Temperature1 As Double := MINIMUM_TEMPERATURE 
  Var Temperature2 As Double := 20 
  Var TemperatureAverage As Double 
  Var TemperatureMessage As Text[100] 
  Var MyPoint As CPoint 

  GetTemperatureMessage(Temperature1, TemperatureMessage) // function calling 
  TemperatureAverage := GetAverageTemperature(Temperature1, Temperature2) // function calling 
  MyPoint.SetColour(0) // class function calling 
End Process
```

# Autoexec 

Just one of the modules can contain a process named Autoexec, that is automatically executed after the control unit is switched on. It is a good practice that Autoexec is placed in the Main module. 

#### Syntax 

```visualbasic
Private Process Autoexec() 
  // your program starts here 
End Process
```

#### Example: module Heating 

```visualbasic
// -------------------------------------------------------------- 
// public constants 
// -------------------------------------------------------------- 

Public Const MINIMUM_TEMPERATURE As Double := 0.0 
Public Const MAXIMUM_TEMPERATURE As Double := 30.0 

// -------------------------------------------------------------- 
// public functions 
// -------------------------------------------------------------- 

Public Function GetTemperatureMessage(Temperature As Double, ByRef Message As Text) 
  If Temperature < MINIMUM_TEMPERATURE Then 
    Message := "Increase temperature" 
  Else 
    Message := "Temperature is OK" 
  End If 
End Function 

Public Function GetAverageTemperature(Temp1 As Double, Temp2 As Double) As Double 
  Return Value (Temp1 + Temp2) / 2 
End Function
```

#### Example: module Main 

```visualbasic
Private Process Autoexec() 
  Var Temperature1 As Double := Heating.MINIMUM_TEMPERATURE // constant from module Heating 
  Var Temperature2 As Double := 20 
  Var TemperatureAverage As Double 
  Var TemperatureMessage As Text[100] 

  // calling function from module Heating 
  Heating.GetTemperatureMessage(Temperature1, TemperatureMessage) 

  // calling function from module Heating 
  TemperatureAverage := Heating.GetAverageTemperature(Temperature1, Temperature2) 
End Process
```

# Init 

The modules can contain a function named Init. The Init function of each module is automatically executed at the start of the system. The Autoexec is automatically executed then. 

#### Syntax 

```visualbasic
Function Init() 
  // initializing of the module 
End Function
```

#### Example: module Heating 

```visualbasic
// Init function is automatically executed at the start of the system 
Function Init() 
  // initializing of the module Heating 
End Function 

// ...
```

#### Example: module Lightening 

```visualbasic
// Init function is automatically executed at the start of the system 
Function Init() 
  // initializing of the module Lightening 
End Function 

// ...
```

#### Example: module Main 

```visualbasic
// Autoexec is automatically executed after modules Heating 
// and Lightening were initialized via their Init functions 
Private Process Autoexec() 
  // ... 
End Process 

// ...
```