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

---

Function or process parameters are used to declare type parameters to be passed to functions and processed. Processes can have only ByVal parameters.

#### Syntax

```visualbasic
[[[Optional] [ByVal]] | ByRef] Name As DataType [:= DefaultValue]
```

 A comma must separate multiple parameters. The parameter modifier Optional indicates if a parameter can be omitted. 

#### Example of an optional parameter

```visualbasic
Function Light(Room As Byte, Optional Level As Byte := 100) 
  // function statements 
End Function
```

In the example, Level is defined using the Optional modifier. If a Level value is not included in the calling, a default value of 100 will be used.

#### Example of a ByRef parameter 

```visualbasic
Function GetTemperatureMessage(Temperature As Long, ByRef Message As Text) 
  If Temperature < 18 Then 
    Message := "Increase temperature" 
  Else 
    Message := "Temperature is OK" 
  End If 
End Function
```

# Optional

It defines that parameter can be included optionally. A DefaultValue for the parameter must be assigned if the Optional modifier is used. The default value will be used if the parameter is omitted. **Only the ByVal parameter can be optional. **It means that is not possible to use Optional ByRef combination.

#### Example of an optional parameter

```visualbasic
Function Light(Room As Byte, Optional Level As Byte := 100) 
  // function statements 
End Function
```


If the function is to change the value of a parameter and at the same time you want the parameter to be of the Optional type, you can use the following .

```visualbasic
Function SetNewValue(newvalue As Byte, Optional previousvalue As AddressOf Long := Nothing) 
  ...
  VariableOf previousvalue := 1
End Function

Process Autoexec()
  Var v As Long
  SetNewValue(10)
  SetNewValue(10, v)
End Process
```


# ByVal

It defines that the parameter is passed by value only. ByVal is used by default. This is a one-way passing of the parameter (variable), meaning that it only passes the variable’s value into the function, but any changes to the parameter will not be passed back out into the variable upon exiting the function. Only the ByVal parameter can be optional. Processes can have only ByVal parameters.

# ByRef

It defines that the parameter is passed by reference. When this option is used, any changes to the parameter from inside a function will be passed back out into the variable upon exit of the function. ByRef parameter cannot be optional. Processes cannot have only ByRef parameters.