Create a global variable with a meaninfull name. (ie dim mPosition as int)
then...
B4X:
Sub TabStrip1_PageSelected (Position As Int)
Log($"Current page: ${Position}"$)
mPosition = Position
End Sub
Sub Scoreboard
Label1.Text = $"${mPosition}"$End Sub
Sub TabStrip1_PageSelected (Position As Int)
Log($"Current page: ${Position}"$)
ScoreBoard(Position)
End Sub
Sub Scoreboard(Position As int)
Label1.Text = $"${Position}"$
End Sub
That is true. But the TabStrip1_PageSelected event is always triggered when you are flipping pages in Tabstrip1. Consequently, a position change occurs.
yes, but if I understand it correctly, the scoreboard sub in this example is a dummy sub, and the real one may be used in more situations than just in sequence with the tabstrip...
If this example sub is a real one, then it would make more sense to just include the label.text change in the tabstrip event
I prefer to pass the variable as an argument. This ensures that the value being passed has not changed to something else in the meantime or part way through the processing. ie. pass the value to guarantee that is does not change to something else that both the originator and receiver subs are not expecting. If it does change to a different value then it can have unwanted and unexpected effects/results.
This is more relevant to apps that use multi-threading but I find it good practice in general to pass the values instead of relying on global variables.
Create a global variable with a meaninfull name. (ie dim mPosition as int)
then...
B4X:
Sub TabStrip1_PageSelected (Position As Int)
Log($"Current page: ${Position}"$)
mPosition = Position
End Sub
Sub Scoreboard
Label1.Text = $"${mPosition}"$End Sub