Hi, is it possible to declare a variable in eg B4XMainpage that is accessible in all pages ?
I want to have i string variable and an numeric variable that i can access everywere.
variables:
Public myString As String
Public myNum As Int
Where must i define them ? Want to access them in my subs
ok then lets declare a string in main named mystring and assign to it the word testword1.
Modify the string in B4XPage1 to testword2 and read it and log it in B4XPage2.
That is what i want to do.
Here you have an example.
I made the variables available in 2 ways:
- Declared in Main Activity
- Declared in a separate Code Module
When the app start both the variables in Main and in Vars module are set to something and logged.
Then you can set both variables to something else clicking the button, that will log them again.
Go to Page 2 and you can log the variables again.
Hope it helps.
I made another example declaring the variables in the B4XMainPage module, that way the principle is cross-platform.
The Starter module does exist only in B4A, and the Main modules are platform specific.
You can modify the variables in any module in Edittext views.
Here you have an example.
I made the variables available in 2 ways:
- Declared in Main Activity
- Declared in a separate Code Module
When the app start both the variables in Main and in Vars module are set to something and logged.
Then you can set both variables to something else clicking the button, that will log them again.
Go to Page 2 and you can log the variables again.
Hope it helps.
I usually end up with at least 2 Code modules that contain global variables. Usually an AppData module which stores App Name and anything else relevant (could go in the Main Module but i like to keep them separate) and a DataConst module which stores Constants used to access Map Data etc.
I often use code modules to make up for the lack of Enums (Ereeel ).
It is convenient to have, for example:
module name: enmFlowers
enmFlowers.ROSE, enmFlowers.DAISY, enmFlowers.LILY, ...