Android Question How to get/asign returned Map from Sub

Jason Wood

Member
Licensed User
Hi,

I have a Sub which returns a map

B4X:
Sub calculateResults(reactionTime As Int)
    Private gameResults As Map
    ...
    Return gameResults
End Sub

I want to use the returned map when this Sub is called i.e

B4X:
Sub otherSub
    ...
    Dim getGameResults As Map
    getGameResults.Initialize
    getGameResults = calculateResults(reactionTime)
End Sub

But this give an error at compile time.

B4X:
B4A line: 211
getGameResults = calculateResults(reactionTime)
javac 1.8.0_131
src\b4a\example\main.java:1113: error: incompatible types: String cannot be converted to MyMap
_getgameresults.setObject((anywheresoftware.b4a.objects.collections.Map.MyMap)(_calculateresults(_reactiontime)));

What am I doing wrong?
 

DonManfred

Expert
Licensed User
Longtime User
Default is to return a String if you don´t specify it.

B4X:
Sub calculateResults(reactionTime As Int) As Map ' <--- !!!
    Private gameResults As Map
    ...
    Return gameResults
End Sub
 
Upvote 0
Top