BigSi Posted February 13, 2003 Posted February 13, 2003 Hi, Im trying to work out how I can access the origional startup form (MainMenu) variables. Normally to do this I would call an instance of a form as it had been created as a new form and had been given an id and the variable I want to access would be stored in a public declaired variable. For instance when I want to access data from a form that I have opened from the main form, I would create the new form like this: Dim frmAccount As New Account() frmAccount.Show() In that form I would have declaired a variable (and assigned a value to it) by doing this at the top of the form Public CLADBLocation As String and to access this variable from the origonal startup form I would use this myNewVariable = frmAccount.CLADBLocation The problem is that I do not know how I can refer to a public variable in the default startup form(MainMenu) as I have not assigned it a name to make it show. Can anyone help? Quote
*Gurus* divil Posted February 13, 2003 *Gurus* Posted February 13, 2003 From within the code in your form called MainMenu, you should set a variable elsewhere, using the Me keyword to refer to the instance of the class from which the code is running. In the case of a main form, it's often best to declare a static ("shared" in vb) public variable in the form and set that in the form's constructor, since there will only be one instance. Other forms can then use this shared reference to get the instance of the main form from anywhere. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
BigSi Posted February 13, 2003 Author Posted February 13, 2003 Excellent - thanks very much, adding shared to declaring the variable has worked perfectly! Thanks for your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.