B4J Question I'm wrong

giannimaione

Well-Known Member
Licensed User
Longtime User
I'm wrong !! ??
the code module returns the list and map values, not the string. Why? I'm confused?
 

Attachments

  • mistake.zip
    2.4 KB · Views: 115

MathiasM

Active Member
Licensed User
String values are passed By Value, List and Map are passed By Reference (just like objects)

You should change the signature of the subroutine and return the Gamma string. Like this:

B4X:
Public Sub subRoutine1 (alfa As List, beta As Map) As String
    alfa.Initialize
    beta.Initialize
    '
    alfa.AddAll(Array As String("One", "Two", "Three", "Four", "Five"))
    '
    beta.Put("ciao", "Hello")
    beta.Put("mondo", "World")
    '
    Return "why doesn't the value return?"
End Sub

And then call the subroutine in your maincode this way:

B4X:
gamma = demo.subRoutine1 (list1, map1)
Log(gamma)
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
See: https://www.b4x.com/android/forum/threads/byref-planned.59794/#post-376816

Map and List are Objects, String is immutable . You can pass a single element array:

B4X:
Dim string1(1) As String
demo.subRoutine1 (list1, map1, string1)
...
Log("? " & string1(0))

demo:
B4X:
Public Sub subRoutine1 (alfa As List, beta As Map, gamma() As String)
   ..
   gamma(0) = "why doesn't the value return?"
End Sub
 
Upvote 0
Top