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

---

A function is a part of a program that can be repeatedly called from diverse locations of the program. A function can be declared only within a module or a class. A function can have parameters, and can return a value. 

See a chapter Class to read about a specific behavior function declared in a class. 

# The function returns no value 

```visualbasic
The function can have parameters and does not return any value. 
[Accessibility] Function Name([Parameters]) [WithAtributes {}]
  [Return] 
End Function
```

### Optional part WithAttributes

This part can contain the following attributes

#### Attribute: Info 

|  |  |  |
| --- | --- | --- |
| Value type | Meaning | Example |
| Text | Text which will be visible in a tooltip window for this property. | Info := "newtemp value can be in a range 0 - 100"<br>Info := "first line\000D\000Asecond line" |

The value of the Info attribute is then displayed in the tooltip of the function

![image](media://d5ebb669-bd19-43ff-819b-bcc15939af8e)

#### Attribute: HiddenInIDE

|  |  |  |
| --- | --- | --- |
| Value type | Meaning | Example |
| Boolean | A symbol with this attribute will not be visible in the IDE ( MyProject Instances, Intellisense windows,…) . **It must be symbol in device driver, applet or graphic collection.** It has no meaaning for symbols in an user module in an unit. | HiddenInIde |

![image-20250916-130212.png](media://6cb5bf6a-f813-4287-8b35-652f99ddf401)



####  Example 

```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
```


####  Example 

```visualbasic
Function SetRequiredTemperature(newtemp As Long) WithAttributes {Info := "newtemp value can be in a range 0 - 100" }
  If newtemp >= 0 And newtemp <= 100 Then
    
  End If 
End Function
```


#### Example 

```visualbasic
Function GetMonthName(Index As Byte, ByRef Name As Text) 
  Select Index 
    Case 1 
      Name := "January" 
    Case 2 
      Name := "February" 
    Case 3 
      Name := "March" 
    Case 4 
      Name := "April" 
    Case 5 
      Name := "May" 
    Case 6 
      Name := "June" 
    Case 7 
      Name := "July" 
    Case 8 
      Name := "August" 
    Case 9 
      Name := "September" 
    Case 10 
      Name := "October" 
    Case 11 
      Name := "November" 
    Case 12 
      Name := "December" 
    Case Else 
      Name := "" 
  End Select 
End Function
```

# Function returns a value 

The function can have parameters and must return a value: Boolean, Byte, Char, Double, Long, or Time. 

The command **Return Value** must be used in all program branches of the function. See the last example. 

```visualbasic
[Accessibility] Function Name([Parameters]) As ReturnType [WithAttributes {}]
  Return Value Statement 
End Function
```

### Optional part WithAttributes

[https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/509083702/Functions#Optional-part-WithAttributes](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/509083702/Functions#Optional-part-WithAttributes) 


#### Example 

```visualbasic
Function AverageTemp(Temp1 As Byte, Temp2 As Byte) As Byte WithAttributes {Info:="The function returns the average value of two temperatures"}
  Return Value (Temp1 + Temp2) / 2 
End Function
```

#### Example 

```visualbasic
Function GetMax(Num1 As Long, Num2 As Long) As Long 
  If Num1 > Num2 Then 
    Return Value Num1 
  Else 
    Return Value Num2 
  End If 
End Function
```

#### Example 

```visualbasic
Function GetNumberOfDays(Year As Long, Month As Byte) As Byte 
  Select Month 
    // 31 days 
    Case 1, 3, 5, 7, 8, 10, 12 
      Return Value 31 
    // 30 days 
    Case 4, 6, 9, 11 
      Return Value 30 
    // February, 28 or 29 days 
    Case 2 
      // if it is a leap 
      If (((Year Mod 4) = 0) And ((Year Mod 100) <> 0)) Or ((Year Mod 400) = 0) Then 
        Return Value 29 
      Else 
        Return Value 28 
      End If 
    // error 
    Case Else 
      Return Value 0 
  End Select 
End Function
```

Note: The command **Return Value** is used in all program branches of the function.