Parameters always transmited by value and not by refernce?

Pantelis

Member
Licensed User
Longtime User
Hi all

In beginners guide in page 232 writes about subs and says: In B4A, the parameters are transmitted by value and not by reference. This is true for primitive and non-primitive variable types?
In page 171-172 says: Primitive types are always passed by value to other subs or when assigned to other variables.
All other types, including arrays of primitives types and strings are categorized as non-primitive types. When you pass a non-primitive to a sub or when you assign it to a different variable, a copy of the reference is passed.

Thanks
 

agraham

Expert
Licensed User
Longtime User
That is correct. The value of a primitive (non-reference type) is the value itself. The value of a non-primitive(reference type) is the value of the reference (pointer) to the non-primitive instance. This means that for a primitive you cannot change the values that other Subs might see for a primitive variable, and that for a non-primitive you can change properties of that particular non-primitive instance and other Subs will see those changes but you can't substitute an entirely different non-primitive instance for the original one passed to your Sub.
 
Last edited:
Upvote 0

Pantelis

Member
Licensed User
Longtime User
Thanks for reply Agraham.

I did not fully understand what you have writen.
Could you please explain with an example?
 
Upvote 0
Top