ByRef method Issue

Hello, please, I have class “test” with .name and .value.

In is dim ab() as test. In ab(0).value set I 5 and call testmethod(ab(0)).

In testmethod Parameters is only “byref a as test.” In testmethod body is a.value = a.value*a.value.

But when I run project it show me Issue - You can’t pass an expression as a parameter that is defined as ByRef testmethod(ab(0))).

What is wrong? It looks good. In webpage1 I put into the method only 1 (ab(0)) and in method I want work with only 1 (a) and both is as test class .

If you want look on my problem, here is sourcecode(it’s only example, not real project)

Because the method takes a “ByRef” parameter you can’t pass in an expression. Unfortunately ab(0) is an expression that says give me the 0th index value of array ab. You will need to set this to a variable before passing it in.

Thank you for response. I tried set in method parameters - byref a() as test
and in body:
a.Append new test
a(0).value = a(0).value*a(0).value
now is issue: Parameter “a” expects class test, but this is class test.
I have no idea what wants xojo say to me…

I found answer.
in webpage1 I copy from ab(0) to ab1, call method with ab1 and then ab(0)=ab1.
dim ab() as test
ab.Append new test
dim ab1 as new test
ab(0).name = “test”
ab(0).value = 5
ab1 = ab(0)
msgbox str(ab(0).value)

Just a note. You don’t need to use “NEW” here. It creates an object that you immediately discard and replace with a reference to ab(0).

Also, if that is how you’re using it, you don’t need to use ByRef at all. Remove ByRef and go back to your original code. Any changes you make to the object you pass in will be reflected in the original, even without ByRef.