Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...