Mark.S Member Licensed User Feb 23, 2019 #1 How do you create a static variable within a class, so that it retains it's value between calls? the only way I can see this being done is by using one of the .tag properties of a view created within the class.
How do you create a static variable within a class, so that it retains it's value between calls? the only way I can see this being done is by using one of the .tag properties of a view created within the class.
Cableguy Expert Licensed User Longtime User Feb 23, 2019 #2 Search for "Constant" If I'm not mistaken, you can use like Private const myvar = 5 as int Upvote 0
Mark.S Member Licensed User Feb 23, 2019 #3 Thanks Cableguy, but a Cont value once declared can't be altered. I need a preserve a variable . Upvote 0
Semen Matusovskiy Well-Known Member Licensed User Feb 23, 2019 #4 Place variables inside Sub Class_Globals Attachments test1.zip test1.zip 8.3 KB · Views: 484 Upvote 0
Computersmith64 Well-Known Member Licensed User Longtime User Feb 23, 2019 #5 Mark.S said: How do you create a static variable within a class, so that it retains it's value between calls? the only way I can see this being done is by using one of the .tag properties of a view created within the class. Click to expand... When you say "between calls" - do you mean references to the variable in the same instance of the class? Or do you mean across different instances of the class? For the former, class member variables act the same way as variables declared in an Activity - ie: as long as the class instance is "alive", the variable will retain whatever value was assigned to it. The only way to maintain a variable across instances of a class is to declare it with an initial value. You can't change a variable value in one instance of a class & then reference that value in another instance. Or maybe I'm misunderstanding your question... - Colin. Upvote 0
Mark.S said: How do you create a static variable within a class, so that it retains it's value between calls? the only way I can see this being done is by using one of the .tag properties of a view created within the class. Click to expand... When you say "between calls" - do you mean references to the variable in the same instance of the class? Or do you mean across different instances of the class? For the former, class member variables act the same way as variables declared in an Activity - ie: as long as the class instance is "alive", the variable will retain whatever value was assigned to it. The only way to maintain a variable across instances of a class is to declare it with an initial value. You can't change a variable value in one instance of a class & then reference that value in another instance. Or maybe I'm misunderstanding your question... - Colin.
Erel B4X founder Staff member Licensed User Longtime User Feb 24, 2019 #6 The question is indeed not clear. You need to better define what you mean with "between calls". A static variable usually means that all class instances share the same variable. You will need to add a static code module for this. You can also put the static variable in Process_Globals of the starter service. Upvote 0
The question is indeed not clear. You need to better define what you mean with "between calls". A static variable usually means that all class instances share the same variable. You will need to add a static code module for this. You can also put the static variable in Process_Globals of the starter service.