Global Variables
-
How does one declare a variable that is available for any form in the project?
-
How does one declare a variable that is available for any form in the project?
Emile Jacobs wrote: How does one declare a variable that is available for any form in the project? Declare a shared public variable in your class, access this variable via MyClassName.MyVariableName. Click here to see my articles and software tools
-
Emile Jacobs wrote: How does one declare a variable that is available for any form in the project? Declare a shared public variable in your class, access this variable via MyClassName.MyVariableName. Click here to see my articles and software tools
We created a shared variable in the class, but we do not know how to declare the class in the different forms!
-
We created a shared variable in the class, but we do not know how to declare the class in the different forms!
The class has to be in the same the project, you don't need to declare it. If the class is only visible in a different name space, then you need to access it via MyNameSpace.MyClassName.MyVariableName. If multiple threads are accessing this variable, make sure thread-safety. Click here to see my articles and software tools
-
The class has to be in the same the project, you don't need to declare it. If the class is only visible in a different name space, then you need to access it via MyNameSpace.MyClassName.MyVariableName. If multiple threads are accessing this variable, make sure thread-safety. Click here to see my articles and software tools
Thanx for the great advice! Everything works perfectly! :laugh::laugh:
-
How does one declare a variable that is available for any form in the project?
Add a new module, such as modMain.vb and in there declare a variable as Public, i.e: Public iMyGlobalVariable as Integer This will give it a global scope.
-
How does one declare a variable that is available for any form in the project?
create a new class called GlobalVariables or what ever you like Then put the variables that you would like to call this is C# code I created a new Class called GlobalVariables.cs on that page the only code that I have is public class GlobalVariables { public string ReportSection = ""; public GlobalVariables() { } } just because I didnt heed it to do anything else. Now on any page that I like I can do this: create an instance of that class GlobalVariables MyVariables = new GlobalVariables(); now assign the values MyVariables.ReportSection = ""; that should do it, William O'Malley