use Namespace to reference a form in a Module?

R

Ron

Hello,

I have added a Namespace to my vb.net project. The
namespace is the name of the project. Then I start the
project from Sub Main

Module1
Sub Main()
Application.Run(New MyProj.Form1)
End Sub
End Module

In a separate module, Module2, I want to reference Form1
so that I can write some data to a textbox, txtData. I
imported the Namespace MyProj to Module2.

Imports MyProj
Imports ... (everything else)

I tried referencing Form1 like this: MyProj.Form1... but
I could not see txtData in a dropdown after Form1. I know
that I could convert Module2 to a Class Module as pass in
txtData to the procedure in the Class Module. But is it
possible to reference Form1 (or really - txtData) in
Module2 as a standard module? Could I do this with the
Namespace?

Thanks,
Ron
 
H

Herfried K. Wagner [MVP]

Ron said:
I tried referencing Form1 like this: MyProj.Form1... but
I could not see txtData in a dropdown after Form1. I know
that I could convert Module2 to a Class Module as pass in
txtData to the procedure in the Class Module. But is it
possible to reference Form1 (or really - txtData) in
Module2 as a standard module? Could I do this with the
Namespace?

You cannot do that using namespaces, that's something different. Namespaces
are used to structure your classes, like directories (a.k.a. folders) in the
file system.

What you want to do is accessing members of an /instance/ of a form from
within a module. You will have to make a reference to your instance of the
form available to the module. There are different ways to do that:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top