Hi
I'm discovering b4a languages features in order to get a large know how. I have two questions:
a) is it possibile to pass an whole array to a sub?
thats to say
dim a(9) as int
.
sub grind_array (x....) <<<<??? how to specify formal parameter???
x(5)=4
end sub
I have tryed to code the following code but I get an error "Use of undeclared array: x"
Sub Globals
Dim b(10), i As Int
For i=0 To 9 : b(i)=i*i : Next
Log("actual param before: "& b(5)) 'Prints b(5) before sub call
S2(b)
Log("actual param after: " & b(5)) 'Prints b(5) after sub call
End Sub
Sub S2(x As Object)
Log("formal param before: "& x) 'Prints x
x(5)=666
Log("formal param after: " &x) 'Prints x
End Sub
b) I read the Erel's post about Variables & Objects in Basic4android. I'm studying about the phrase "
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." and about "
All types can be treated as Objects". So I tryed another example passing the single array cell but it seems that it's behaving as value passing. let's see.
Sub Globals
Dim b(10), i As Int
For i=0 To 9 : b(i)=i*i : Next
Log("actual param before: "& b(5)) 'Prints b(5) before sub call
S2(b(5))
Log("actual param after: " & b(5)) 'Prints b(5) after sub call
End Sub
Sub S2(x As Int)
Log("formal param before: "& x) 'Prints x
x=666
Log("formal param after: " & x) 'Prints x
End Sub
I thought that the correct value for the actual param after the s2 call would be 666 and not 25.
So, could you help me understanding this topic.
cheers
alex