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

---

# ParamArray

ParamArray is a group of parameters to be passed to functions and processes at the ParamArray position. The number and data types of entered parameters must be the same as the number and data types of declared function/process parameters. 

#### Example 

Second parameter of function <u>[ConcatenateText](/wiki/spaces/CVCHELP/pages/512327836/Text#ConcatenateText)</u> is ParamArray. At the ParamArray position are passed more parameters. 

```visualbasic
Var FirstName As Text := "Peter" 
Var Result As Text[100] 

ConcatenateText(Result, "Hello ", FirstName, ", how are you?") 
DebugPrint(Result)
```

It prints to the debug window: 

```visualbasic
Hello Peter, how are you?
```

Values from ParamArray in your function must be stored into function variables to work with them. 

#### Syntax of getting ParamArray value inside a function 

```visualbasic
VariableName := VariableOf ParamArray[ParamIndex]
```

#### Example 

Function Display3Parameters displays three parameters entered as ParamArray. 

```visualbasic
Function Display3Parameters(ParamArray) 
  Var n1 As Long := VariableOf ParamArray[1] 
  Var n2 As Long := VariableOf ParamArray[2] 
  Var t As Text[100] := VariableOf ParamArray[3] 

  DebugPrint(n1, n2, t) 
End Function 

Private Process Autoexec() 
  Display3Parameters(1, 2, "Good morning.") 
End Process
```

It prints to the debug window: 

```visualbasic
1 
2 
Good morning.
```

#### Example 

Function DisplaySum sums numbers and displays a result. A function ParamArrayCount is used. 

```visualbasic
Function DisplaySum(ParamArray) 
  Var i As Long 
  Var Result As Long := 0 
  Var Summand As Long 

  For i := 1 To ParamArrayCount 
    Summand := VariableOf ParamArray[i] 
    Result += Summand 
  End For 

  DebugPrint(Result) 
End Function 

Private Process Autoexec() 
  DisplaySum(1, 2) 
  DisplaySum(1, 2, 3) 
  DisplaySum(1, 2, 3, 4) 
  DisplaySum(1, 2, 3, 4, 5) 
End Process
```

It prints to the debug window: 

```visualbasic
3 
6 
10 
15
```

#### Example 

Function DisplayMessageParameters displays parameters of three different types of messages. MESS_NUMBERS has two number parameters, MESS_TEXTS has two text parameters, and mixed MESS_MIXED has two number and two text parameters. The type of the message is the first parameter. 

```visualbasic
Const MESS_NUMBERS As Byte := 1 
Const MESS_TEXTS As Byte := 2 
Const MESS_MIXED As Byte := 3 

Function DisplayMessageParameters(MessId As Long, ParamArray) 
  Var n1 As Long 
  Var n2 As Long 
  Var t1 As Text[100] 
  Var t2 As Text[100] 

  Select MessId 
    Case MESS_NUMBERS 
      n1 := VariableOf ParamArray[1] 
      n2 := VariableOf ParamArray[2] 
      DebugPrint(n1, n2) 
    Case MESS_TEXTS 
      t1 := VariableOf ParamArray[1] 
      t2 := VariableOf ParamArray[2] 
      DebugPrint(t1, t2) 
    Case MESS_MIXED 
      n1 := VariableOf ParamArray[1] 
      n2 := VariableOf ParamArray[2] 
      t1 := VariableOf ParamArray[3] 
      t2 := VariableOf ParamArray[4] 
      DebugPrint(n1, n2, t1, t2) 
  End Select 
End Function 

Private Process Autoexec() 
  DisplayMessageParameters(MESS_NUMBERS, 1, 2) 
  DisplayMessageParameters(MESS_TEXTS, "Hello,", "how are you?") 
  DisplayMessageParameters(MESS_MIXED, 111, 222, "I am fine,", "thank you.") 
End Process
```

The first calling of DisplayMessageParameters prints to the debug window: 

```visualbasic
1 
2
```

The second calling of DisplayMessageParameters prints to the debug window: 

```visualbasic
Hello, 
how are you?
```

The third calling of DisplayMessageParameters prints to the debug window: 

```visualbasic
111 
222 
I am fine, 
thank you.
```

# ParamArrayCount 

The function gets a count of ParamArray passed as a parameter. 

#### Syntax 

```visualbasic
ParamArrayCount() As Long
```

#### Example 

Function DisplaySum sums numbers and displays a result. 

```visualbasic
Function DisplaySum(ParamArray) 
  Var i As Long 
  Var Result As Long := 0 
  Var Summand As Long 

  For i := 1 To ParamArrayCount 
    Summand := VariableOf ParamArray[i] 
    Result += Summand 
  End For 

DebugPrint(Result) 
End Function 

Private Process Autoexec() 
  DisplaySum(1, 2) 
  DisplaySum(1, 2, 3) 
  DisplaySum(1, 2, 3, 4) 
  DisplaySum(1, 2, 3, 4, 5) 
End Process
```

It prints to the debug window: 

```visualbasic
3 
6 
10 
15
```