By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

When to use "imports" statement?

P: n/a
Hello,
I want to ask about "imports" statement. Some projects must be
inserted with "imports xxxx" statements before beginning coding. But
how do i know when to use or do i have to use "imports" statement?
How will i know which "imports" will my project need? From books or
how can i guess?

Thanks...

Oct 16 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
Hello,
I want to ask about "imports" statement. Some projects must be
inserted with "imports xxxx" statements before beginning coding. But
how do i know when to use or do i have to use "imports" statement?
How will i know which "imports" will my project need? From books or
how can i guess?

Thanks...
You use imports to bring in definitions. For example lets say you want to
use the methods provided within the System.IO namespace (for example
GetTempFileName).

Now without imports you could use the following:

Dim str as String = System.IO.Path.GetTempFileName()

With the imports
Imports System.IO

your code would be:

Dim str as String = Path.GetTempFileName()
Now there are lots of namespaces that hold identical interfaces.

There are both:

Microsoft.VisualBasic.MyServices.FileSystemProxy.G etTempFileName() As String
and
System.IO.Path.GetTempFileName() As String

to use the statement

Dim str as String = GetTempFileName()
you would add the correct imports statement and then you would have good
code.
This is a big subject but I hope what I have written helps.

Lloyd Sheen

Oct 16 '07 #2

P: n/a
On Oct 16, 10:20 pm, "Lloyd Sheen" <a...@b.cwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:11**********************@i38g2000prf.googlegr oups.com...
Hello,
I want to ask about "imports" statement. Some projects must be
inserted with "imports xxxx" statements before beginning coding. But
how do i know when to use or do i have to use "imports" statement?
How will i know which "imports" will my project need? From books or
how can i guess?
Thanks...

You use imports to bring in definitions. For example lets say you want to
use the methods provided within the System.IO namespace (for example
GetTempFileName).

Now without imports you could use the following:

Dim str as String = System.IO.Path.GetTempFileName()

With the imports
Imports System.IO

your code would be:

Dim str as String = Path.GetTempFileName()

Now there are lots of namespaces that hold identical interfaces.

There are both:

Microsoft.VisualBasic.MyServices.FileSystemProxy.G etTempFileName() As String
and
System.IO.Path.GetTempFileName() As String

to use the statement

Dim str as String = GetTempFileName()
you would add the correct imports statement and then you would have good
code.

This is a big subject but I hope what I have written helps.

Lloyd Sheen
Hi Mr. Sheen,
Thanks for your samples and explanation. As i understand, "imports" is
used to shorten syntax. It's a bit like "header files" in C++ i
suppose. And without imports statement, the same code function can be
coded within a line, like shown in your examples.

Thank you.

kimiraikkonen

Oct 16 '07 #3

P: n/a
You can also use Imports to abbreviate a namespace, such as
Imports F = System.Windows.Forms

or if you have your own project of custom user controls and other objects
called, for example, MyUserControls, and your exe project holds a reference
to that project or dll...In the exe's classes you could use...

Imports C = MyUserControls

Then when you type "C." you will see all of your custom controls and objects.

"kimiraikkonen" wrote:
On Oct 16, 10:20 pm, "Lloyd Sheen" <a...@b.cwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:11**********************@i38g2000prf.googlegr oups.com...
Hello,
I want to ask about "imports" statement. Some projects must be
inserted with "imports xxxx" statements before beginning coding. But
how do i know when to use or do i have to use "imports" statement?
How will i know which "imports" will my project need? From books or
how can i guess?
Thanks...
You use imports to bring in definitions. For example lets say you want to
use the methods provided within the System.IO namespace (for example
GetTempFileName).

Now without imports you could use the following:

Dim str as String = System.IO.Path.GetTempFileName()

With the imports
Imports System.IO

your code would be:

Dim str as String = Path.GetTempFileName()

Now there are lots of namespaces that hold identical interfaces.

There are both:

Microsoft.VisualBasic.MyServices.FileSystemProxy.G etTempFileName() As String
and
System.IO.Path.GetTempFileName() As String

to use the statement

Dim str as String = GetTempFileName()
you would add the correct imports statement and then you would have good
code.

This is a big subject but I hope what I have written helps.

Lloyd Sheen

Hi Mr. Sheen,
Thanks for your samples and explanation. As i understand, "imports" is
used to shorten syntax. It's a bit like "header files" in C++ i
suppose. And without imports statement, the same code function can be
coded within a line, like shown in your examples.

Thank you.

kimiraikkonen

Oct 17 '07 #4

P: n/a
Kimi,

It has nothing to do with headers. There is no need to use it, however it
makes your program easier to write and easier to maintain.

Your main question however was in my idea where to find it. Look in MSDN and
see what namespace a class uses. Have then a look in your references (to
find in project and with the right click on the folder for that in your
project solution) if you have that already then you can use the import. If
not than select it. It area DLL's what stends in .Net for a Library. They
contains the classes which you can use.

The Imports says nothing more than that you have an abbrivation, it imports
nothing. In this case I find the C# equivalent Using much more fitting for
the purpose.

Cor

Oct 17 '07 #5

P: n/a
On Oct 17, 7:14 am, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Kimi,

It has nothing to do with headers. There is no need to use it, however it
makes your program easier to write and easier to maintain.

Your main question however was in my idea where to find it. Look in MSDN and
see what namespace a class uses. Have then a look in your references (to
find in project and with the right click on the folder for that in your
project solution) if you have that already then you can use the import. If
not than select it. It area DLL's what stends in .Net for a Library. They
contains the classes which you can use.

The Imports says nothing more than that you have an abbrivation, it imports
nothing. In this case I find the C# equivalent Using much more fitting for
the purpose.

Cor
Yes, "using" looks like "imports". Has some namespace decleractions.
Thanks.

Oct 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.