No - use a module. Put it in a folder common to all the projects in which you want to use them. When you add the module to the project(s) make sure you "Add as Link."Add as link is the same as adding it to your project, but it doesn't make a local copy. Instead it uses the one in your common folder. To add as link begin by adding it the way you normally do, but in the dialog where you click on "Add" you will notice a little drop-down arrow. Add as Link is one of the choices.
Be careful though - any changes you make to the common module will impact every program that uses it - and you WILL forget all of the programs that use it.
And next I want to challenge you to seek a better design...
Certainly there are times this approach makes sense (I'm not one of those "absolute" guys that will say "never do this.") There may be a better way to do what you need. Instead of globally referring to variables perhaps it will work better to make sure you are passing values into subs and functions, then handing them back as necessary. Make use of ByRef so any change you make to the variable will be reflected upon the function/sub return. Make use of ByVal if you want the sub/function to work with its own new copy of the variable. This can be a little tricky in VB though. Elementary types like integers will get copied in ByVal passing, but strings and instantiated objects will still pass in a reference and changes will be reflected up the chain unless you pass in a cloned copy. To avoid changing a string globally you can pass in string.clone. Some native dotnet objects support cloning - for your own objects you will need to implement iCloneable and decide if it needs to be shallow or deep. Implementing a deep-cloned class can be daunting...
Comment