Keyword

# ByRef

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to pass a parameter by reference.

## Usage

``` xojo
ByRef parameter As DataType
```

| Part      | Type                | Description                                                       |
|-----------|---------------------|-------------------------------------------------------------------|
| parameter |                     | Parameter to be passed by reference. *parameter* can be an array. |
| DataType  | Any valid data type | The data type of the parameter.                                   |

## Notes

Parameters passed by value are treated as local variables inside the method-just like variables that are created using the `Var</api/language/var>` statement. This means that you can modify the values of the parameters themselves rather than first assigning the parameter to a local variable. For example, if you pass a value in the parameter "x", you can increment or decrement the value of x rather then assigning the value of x to a local variable that is created using `Var</api/language/var>`.

To pass a parameter by reference, you use the <span class="title-ref">ByRef</span> keyword in the parameter declaration for the method. If you precede a parameter name by the keyword <span class="title-ref">ByRef</span>, you pass information by reference. When you pass information by reference, you actually pass a pointer to the variable containing the information. The practical advantage of this technique is that the method can change the values of each parameter. When you pass parameters by value, it doesn't do this because in effect the parameter only represents a copy of the data itself.

<div class="note">

<div class="title">

Note

</div>

Passing array parameters with <span class="title-ref">ByRef</span> is not currently supported for Android.

</div>

## Sample code

The following method declaration uses \`ByRef\`:

``` xojo
ByRef amount As Double
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When you click OK to save the new method, the Sub statement in the Code Editor shows that the parameter has been declared \`ByRef\`:

``` xojo
Protected Sub AddTax(ByRef amount As Double)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The AddTax method takes one parameter, amount, that is called <span class="title-ref">ByRef</span>.

The method code is:

``` xojo
amount = amount * 1.08
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

AddTax is called in the following code:

``` xojo
Var a As Double
a = 3
AddTax(a)
TextField1.Text = a.ToString
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`ByVal</api/language/byval>` keyword.

</div>
