Is it a good practice using global variables in a VB (.NET) application in order to exchange data between forms?
As global variable I mean a public variable defined in a module and not a public member or property of a class. Moreover as my personal rule I never access a global variable from a class, but I pass the values to the class via functions.
I know, I am not a friend a global variables and their abuse, but there are some cases in forms data exchange where they seem to be to only way to make simple/clear code.
Example 1: my application is started with command line args. I need to access to this arguments in all my forms: i just read and validate the arguments in my MDI-load event and then store them in global variables. Thus I can read these values in a very simply way from all my forms.
Example 2: I'm developing a program that write application's events in a EventLog protocol (like the Windows EventLog). I wrote the class EventLog that handles adding, showing, saving, sorting the EventLog. Then I put in a module the global variable gEventLog as istance of the class EventLog and created the object when the MDI form is loaded. In this way I have a global variable and I can handle the EventLog from each forms (MDI and child) in my program. On the other hand I could have created EventLog as public member or property of my MDI form and it would have been the same.
I found and read already some discussions, but more tailored on C programming or basic discussion issues, like in:
http://c2.com/cgi/wiki?GlobalVariablesAreBad
and on vb this:
Declare global variables in Visual Studio 2010 and VB.NET
Any suggestions about the particular case of data exchange between forms (and not between classes and other components of the program)? Thank you.