That's pretty straight foward ...
Private Shared myconnstring As String
Public Shared Property connectionString() As String
Get
Return myconnstring
End Get
Set(ByVal value As String)
myconnstring = value
End Set
End Property
That way, these variables are "shared" between all instances of the class you define them in. You can keep the rest of your code unchanged, you could even leave the modified code I provided you as it is (altough it is unnefficient to create the forms once here and once when you show it).
--
Just some definitions of OOP concepts that seem in order :
Class or type : Model on which to create objects. Defines a list of preoperties and methods that define teh state and behavior of each object.
Object or instance : One use of a class. When you use the New keyword, you create an instance of that class.
Instance variable : One of the property of an object. This is a reference to another object or a value that describes the current object. By changing that value/reference, you affect the state of the object.
State of an object : General term for refering to the list of all instance variables of an object, which inherently defines it. Generally speaking, two object with in same state should behave the same.
Behavior of an object : Way it interacts with other object and itselves through the use of its methods.
--
Using these definitions, an instance variable can be different between two instances of a class (hence you would set the value in the first object wihtout affecting the other). However, shared or static variables are stored at class level and are the same for every instances of the class they are defined in. They do not define the state of the object. They can be used by the class' name directly or through an instance's reference. They are not inherited (although accessing a super class' static field may be possible through a reference of the sub class') and cannot be overriden.
The latest results in the fact that using a reference of type SuperClass, I can access the static properties and methods of the SuperClass even if the type of the object (not the reference) is of type SubClass and contains static fields and methods that shadow that of SuperClass which it inherits. The type of the reference is always the same type or the type of a super class of the object it refers to (which is why casting an object to a type that is not its type of that of a super class will throw an Exception).
Many a programmer are unaware of those technicalities, but they are very important, not always for writing code but often for debugging it. Wow, I was in fire tonight

!