Can't access value from Process Global

winnunez

New Member
I have currently have 4 modules, In the module below I declared an Int result.

B4X:
'Activity module
Sub Process_Globals
   
   Dim MP As MediaPlayer 
   Dim result As Int
   
End Sub

Sub Globals
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layout2") 'Load the layout file.
   

End Sub

Sub Button1_Click
     MP.Initialize2("MP")
    MP.Load(File.DirAssets, "lightsaber.mp3")
    MP.Play
    result = Msgbox2("Did the baby react?", "Attention", "Yes", "Cancel", "No", LoadBitmap (File.DirAssets, "important.png"))
    If result = DialogResponse.Positive Then StartActivity(Postive)
     
    If result = DialogResponse.Negative Then StartActivity(Postive)

End Sub
    
Sub Button2_Click
     StartActivity(Button)

End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

However when I'm trying to access the result variable in the module below. An error comes up when compiling that the result variable is undeclared.

B4X:
'Activity module
Sub Process_Globals
   

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layoutp")
   Msgbox(result,"Hello")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

When I declare a variable in process global, shouldn't it be accessible across all the modules?
 

Kevin

Well-Known Member
Licensed User
Longtime User
You need to include the module name that the global variable is contained/declared in....

So assuming result is in a module called Main:

B4X:
Msgbox(Main.result,"Hello")
 
Upvote 0
Top