We help IT Professionals succeed at work.

passing variable

b001 asked
Hi experts
I have a menu forms that has variable passx declared as below

public passx as string

how can use this variable in my form login and return the value back to menu

Watch Question


Add there a module and move your declaration there, then it's available program vide(on all forms).

You have two choices:

1) As Matti suggests, create a separate module file (in Solution Explorer, right-click on your project, choose Add, and choose Module). In this file, put all the public variables that you want to be available throughout your project/solution (also known as global variables; some purists dislike global variables, but I find them extremely useful). This is also a good place to put functions you write that you want to use in multiple forms.

2) If you want to keep the variable in the menu form but reference it from the login form, you can do that if one of them calls the other. If the menu form (with passx declared) is the main form for the project, and the login form is called by it, then do the following steps:

In the menu form, where you create the login form:

Dim formLoginNew as New formLogin
formLoginNew.Owner = Me

In the Load event of the login form:

dim formOwner as formMenu
formOwner = Me.Owner

Now, anywhere in the login form, you can reference formOwner.passx:

formOwner.passx = txtPassword.Text

Obviously, you'll have to adjust the names to fit your application, but I hope this is clear. If not, ask back.