Process_Globals variable question?

wes58

Active Member
Licensed User
Longtime User
I have declared some variable in Sub Process_Globals in Main Activity.
I have assigned some values to those variables.
When I open Activity2 and try to use those variables (with the values from Main Activity) I get an error message "Error description: Undeclared variable 'info_cur' is used before it was assigned any value."

Main Activity
Sub Process_Globals
Dim info_cur As Int
Dim info_curTab As Int
Dim info_inst As Int

info_cur = 5 'this is an example only, those values will be changed
info_curTab = 3 'in the program. They are not constant values.
info_inst = 20
end sub

Activity2
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Info")
ListView1.AddTwoLines("Cable Rating (A): " & info_cur, "Ref. Table: " & info_curTab)
....
....
End Sub

Is there a way to pass variable values from one Activity to another?
Is there a way to hide one layout (file) and display another layout in Main Activity? This way wouldn't be a problem with access to variables.
Is there an equivalent statement to "GoTo LabelName" to bypass part of the code in the sub?
 

JesseW

Active Member
Licensed User
Longtime User
Erel said not too long ago that he was planning on implementing some kind of global space where modules could share sub's. I personally thought Sub Process_Globals could share variables between modules, as shown in the excerpt below...

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

ps. wes58, wrap code in CODE tags, not QUOTE tags. Highlight the text you want to show inside the quote box and click the [#] icon in the editor's toolbox.
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
Erel said not too long ago that he was planning on implementing some kind of global space where modules could share sub's. I personally thought Sub Process_Globals could share variables between modules, as shown in the excerpt below...

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

I found the solution in one of the previous threads.
Did you add the prefix Main to the variables in the other activity?

Sub Process_Globals
Dim Var AsDouble

In the other activity.
Main.Var = 1.23

It's the same as with the Modules in B4PPC.
You can also declare process global variables in other activities, then you must add the activity name as the prefix for the variables in other activities.
 
Last edited:
Upvote 0
Top