Globals in Subs

Jim Brown

Active Member
Licensed User
Longtime User
Does b4a have a mechanism for having variables which remember their values yet are unique to the sub (that is, not 'global' to the whole program)?

Here for example, I want the variable n to be private in the test() sub yet retain its value. Currently, the value is always re-initialised each call:
B4X:
Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
   For i=1 To 5
      test
   Next   
End Sub

Sub test()
   Dim n As Int
   n=n+1
   Log(n)
End Sub
 
Last edited:
Top