Hello!

I have program that consists of multiple forms. Each of the forms share a common variable which I stored in the main form. But to access the variable from another form, I have to type something quite long like this:

MainForm.CommonVar.Function(arg1, arg2, arg3, arg8)

I use this many times in the other forms and would like to know if there is any way I could use it just like this:

CommonVar.Function(arg1, arg2, arg3, arg8)

I tried to Import the whole MainForm namespace. It worked but it reveals all the variables in the main form, something which I don't want. I used this code to import the MainForm namespace:

Imports RootNamespace.MainForm

Are there any other way which can make only the required variable visible in all forms?

you could add a Module to your project and put the function as "friend Function" in this module.

after that you can call this function from every form inside your project without importing namespaces.

you could add a Module to your project and put the function as "friend Function" in this module.

after that you can call this function from every form inside your project without importing namespaces.

Thank you for your suggestion on 'Friend'! It worked!

This question has already been answered. Start a new discussion instead.