iOS Question How to find out what procedure called the function?

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

Let's say the sub A called the function B. And the sub D called the function B.

Is it possible in function B to find out what sub called this function?


B4X:
Private sub A

dim str as String

str=B()

End Sub

Private sub D

dim str as String

str=B()

End Sub

Private sub B as String

dim caller as String

caller=..... ' How to get this info?

    if caller="sub A" then
          return "Hello A"
    else
          return "Hello B"
    end if

End Sub
 

Cableguy

Expert
Licensed User
Longtime User
Dim caller as public in globals. That way it will be visible throughout the module, and define it when calling.
Another possibility is to add it as an argument when calling the sub, like

Sub A
.....
Callsub D("A")
End sub A

Sub B (calling_sub as string)
Log (calling_sub)
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Dim calle as public in globals. That way it will be visible throughout the module
Thanks for your advice. But I need to modify my code a lot. I thought maybe there is something that I can use in the function body only.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I edited my reply, easier to do, not too many changes
 
Upvote 0

epiCode

Active Member
Licensed User
Set a variable in source subs (different for each sub)
check in target sub then reset it.

thats the easiest way to go if there are not too many source subs.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Set a variable in source subs (different for each sub)
check in target sub then reset it.

thats the easiest way to go if there are not too many source subs.
Thanks, I will do that. I expected that some magic can be done directly in the function body.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…