M Mahares Expert Licensed User Longtime User Jan 20, 2015 #1 The object of this exercise is to use SubDelayed2 in Activity2 to display a value in MAIN activity. But the value returned is blank. I can move the sub to Main and get the value I want, but that will defeat the purpose of the exercise. Is there any way to modify my code and stick with SubDelayed2 to display the correct value? Thank you 'MAIN activity: Code: Copy Sub Process_Globals Dim MyTeam As String End Sub Sub Activity_Create(FirstTime As Boolean) StartActivity(Activity2) End Sub Sub GetTeam(s As String) As String MyTeam= "My favorite soccer team is located in " & s End Sub 'Activity2: Code: Copy Sub Activity_Create(FirstTime As Boolean) CallSubDelayed2(Main,"GetTeam","France") Log("My Team is: " & Main.MyTeam) 'Displays a blank value, Why??? End Sub
The object of this exercise is to use SubDelayed2 in Activity2 to display a value in MAIN activity. But the value returned is blank. I can move the sub to Main and get the value I want, but that will defeat the purpose of the exercise. Is there any way to modify my code and stick with SubDelayed2 to display the correct value? Thank you 'MAIN activity: Code: Copy Sub Process_Globals Dim MyTeam As String End Sub Sub Activity_Create(FirstTime As Boolean) StartActivity(Activity2) End Sub Sub GetTeam(s As String) As String MyTeam= "My favorite soccer team is located in " & s End Sub 'Activity2: Code: Copy Sub Activity_Create(FirstTime As Boolean) CallSubDelayed2(Main,"GetTeam","France") Log("My Team is: " & Main.MyTeam) 'Displays a blank value, Why??? End Sub
thedesolatesoul Expert Licensed User Longtime User Jan 20, 2015 #2 No. CallSubDelayed will be executed when the main thread is emtpy i.e. when Activity_Create stops running. CallSub will do an immediate call though. Upvote 0
No. CallSubDelayed will be executed when the main thread is emtpy i.e. when Activity_Create stops running. CallSub will do an immediate call though.
M Mahares Expert Licensed User Longtime User Jan 20, 2015 #3 Thanks TDS. Do you mean CallSub2(Main,"GetTeam","France") instead of using CallSub because I need to pass the parameter "France". I even tried callSub2 but it still shows blank. Upvote 0
Thanks TDS. Do you mean CallSub2(Main,"GetTeam","France") instead of using CallSub because I need to pass the parameter "France". I even tried callSub2 but it still shows blank.
thedesolatesoul Expert Licensed User Longtime User Jan 20, 2015 #4 The thing is you are trying to call one sub in another activity. Thinking about the activity life cycle, code in another activity cannot be executed unless it is active. And two activities cannot be active at the same time. Its not a matter of where the sub is 'placed'. Upvote 0
The thing is you are trying to call one sub in another activity. Thinking about the activity life cycle, code in another activity cannot be executed unless it is active. And two activities cannot be active at the same time. Its not a matter of where the sub is 'placed'.
RandomCoder Well-Known Member Licensed User Longtime User Jan 20, 2015 #5 I think you should stick with callsubdelayed2 which will work, but move the log statement into Activity1 immediately after setting MyTeam. Obviously you won't need to prefix it with the 'main' once in this activity. I think it will then work. Upvote 0
I think you should stick with callsubdelayed2 which will work, but move the log statement into Activity1 immediately after setting MyTeam. Obviously you won't need to prefix it with the 'main' once in this activity. I think it will then work.
M Mahares Expert Licensed User Longtime User Jan 20, 2015 #6 Thanks again TDS and RandomCoder. Here is the final solution that finally worked. Putting this code in Activity2: Code: Copy Sub Activity_Create(FirstTime As Boolean) If Not(IsPaused(Main)) Then CallSub2(Main,"GetTeam","France") 'CallSubDelayed2 also works Log("My Team is: " & Main.MyTeam) End If End Sub Last edited: Jan 21, 2015 Upvote 0
Thanks again TDS and RandomCoder. Here is the final solution that finally worked. Putting this code in Activity2: Code: Copy Sub Activity_Create(FirstTime As Boolean) If Not(IsPaused(Main)) Then CallSub2(Main,"GetTeam","France") 'CallSubDelayed2 also works Log("My Team is: " & Main.MyTeam) End If End Sub