Is there any way to execute a command inside a variable?

Catom

Member
Licensed User
Longtime User
Let me explain my problem...

I have 3 activities:

  • FindByGeo
  • FindByName
  • geoMapDetails

Both "FindByGeo" and "FindByName" have same Process Globals (they manage the same information, but searched by different means)

Right now "geoMapsDetails" obtains its data calling FindByGeo.Var1, FindByGeo.Var2 and so on.

I want to use the same "geoMapsDetails" with "FindByName" activity, but to be able to do that, I need to know which activity I came from.

Reading the forum, I found that I can use CallSubDelayed2 to send a specific variable, so I used: CallSubDelayed2(geoMapDetails,"ContinueExec", "FindByName") and now I can determine which Activity I came from.

Now my problem is (and where the post title came from :) ) to select which variables do I use. To avoid typing lots of if's and then's, I'd like to know if is there any way to do this:

Dim Origin as String
Dim MyVar as String
Dim RealContent as String

RealContent = execute(Origin & MyVar)

Where Origin & MyVar represents FindByName.Var1, and RealContent could countain the result.

I hope I explained myself succesfully :D

Thanks a lot!
 

edgar_ortiz

Active Member
Licensed User
Longtime User
NO... there are not Macro-substitution in B4A.

But you can program all the scenarios and use a parameter for the respective scenario.

Regards,

Edgar
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Do it the 'android' way and use an Intent to start your geoMapDetails activity, passing the values as part of the Intent:

B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetComponent("your.application.package.name.here/.geomapdetails")
Intent1.PutExtra("Var1", Var1)
Intent1.PutExtra("Var2", Var2)
StartActivity(Intent1)

You'd use that in FindByGeo and FindByName - it replaces 'StartActivity(geoMapDetails)'.

Then in geoMapDetails:

B4X:
Sub Activity_Create(FirstTime As Boolean)

   Dim Intent1 As Intent
   Intent1=Activity.GetStartingIntent
   If Intent1.HasExtra("Var1") AND Intent1.HasExtra("Var2") Then
      Dim Var1 As String=intent1.GetExtra("Var1")
      Dim Var2 As String=intent1.GetExtra("Var2")
   Else
      '   handle the activity being started with an Intent that doesn't contain the required values
   End If
   
End Sub

This example assumes your values are String values, all primitive data types can be passed as intent extras (Int, Float etc), i think custom Types can also be passed as intent extras but you'd have to check that.

Martin.
 
Upvote 0
Top