Global variables

rfresh

Well-Known Member
Licensed User
Longtime User
I'm declaring a global variable as follows:

B4X:
Sub Process_Globals
   Dim pNightimeIntensity As Int

This var is in my main activity. In my setup activity I am changing the value of this variable. Then I exit the setup activity and resume my main activity however, this variable is 0. I set it to 15 in the setup activity.

From what I read, if I declare a var in the Process_Globals they can be seen in any module. Is this not a true global variable? How do I declare a var that both my main and setup activities can access and change, etc.?

Thanks...
 

barx

Well-Known Member
Licensed User
Longtime User
Are you changing it's value with

B4X:
main.pNightimeIntensity = 15

??
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
If you are running two activities, I don't think the second one can read any variables from the other activity, it is paused. If you have two activities, in the setup activity, set the variable and write it to a file and read the value back in when you return to the main activity.

If you are using a code module, you set the value with main.myvariable=15
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If you are running two activities, I don't think the second one can read any variables from the other activity, it is paused.
No, a variable declared in a Process_Globals routine can also be accessed from another Activity. The variable name must have the Module name where it was declared as a prefix in the other modules like shown in the previous posts.

Best regards.
 
Upvote 0
Top