Using a returned array

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

Why does

mainWindow.StatusLabel.Text = CalcTotals(2)

not work?
Error:

Too many arguments: got 1, expected only 0

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

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)

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.

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