Accessing Default startup form variable

BigSi

Newcomer
Joined
Feb 6, 2003
Messages
22
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:

Visual Basic:
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

Visual Basic:
Public CLADBLocation As String

and to access this variable from the origonal startup form I would use this
Visual Basic:
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?
 
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.
 
Excellent - thanks very much, adding shared to declaring the variable has worked perfectly!

Thanks for your help.
 
Back
Top