# Using a returned array

**URL:** <https://forum.xojo.com/t/using-a-returned-array/31155>\
**Category:** General\
**Created:** [April 29, 2016, 11:45am UTC](https://forum.xojo.com/t/using-a-returned-array/31155 "2016-04-29T11:45:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [April 29, 2016, 11:45am UTC](https://forum.xojo.com/t/using-a-returned-array/31155/1 "2016-04-29T11:45:29Z")

</div>

I have a function CalcTotals() that returns a String array with 3 elements.

Why does

```auto
mainWindow.StatusLabel.Text = CalcTotals(2)
```

not work?  
Error:

```auto
Too many arguments: got 1, expected only 0
```

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [April 29, 2016, 11:52am UTC](https://forum.xojo.com/t/using-a-returned-array/31155/2 "2016-04-29T11:52:29Z")

</div>

Don’t put the arrays bounds in the argument. Just use  
mainWindow.StatusLabel.Text = CalcTotals()

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [April 29, 2016, 12:07pm UTC](https://forum.xojo.com/t/using-a-returned-array/31155/3 "2016-04-29T12:07:44Z")

</div>

You cannot do that in Xojo. You need to assign the array to a local variable first:

`Dim tmp() As String = CalcTotals()
mainWindow.StatusLabel.Text = tmp(2)`

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [April 29, 2016, 12:15pm UTC](https://forum.xojo.com/t/using-a-returned-array/31155/4 "2016-04-29T12:15:16Z")

</div>

Or refactor your method to accept the bound argument and return a simple string instead.

For instance

[code]Function CalcTotals(Bound as Integer) As String  
//Do whatever you need with an array  
// For instance  
Dim Result() As string  
// Do things with Result

If Bound \<= Result.Ubound-1 then  
Return Result(Bound)  
else  
Return “”  
end if  
End Function[/code]

Then your code `mainWindow.StatusLabel.Text = CalcTotals(2)` will work.

---

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [April 29, 2016, 12:50pm UTC](https://forum.xojo.com/t/using-a-returned-array/31155/5 "2016-04-29T12:50:06Z")

</div>

Thanks for the replies. I got it working with the intermediate var.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:17pm UTC](https://forum.xojo.com/t/using-a-returned-array/31155/6 "2020-10-29T18:17:50Z")

</div>


