473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

When to use "imports" statement?

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
5 13320

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dgates | last post by:
Has anyone typed up an index for the O'Reilly book "C# and VB.NET Conversion?" I'm just learning C#, and often using this little book to see which VB.NET terms translate directly to some term in...
2
by: darrel | last post by:
I've built a control. At the top of my control, I have this: Imports Microsoft.VisualBasic Then, later, I call a function like this: DateTime.Now.Year.ToString() This works fine on my...
1
by: A. Nonymous | last post by:
If I make my own Namespace do I have to compile it to a DLL before I can use the line: Imports MyNamespace anywhere? TIA
3
by: KRC | last post by:
I am using an external object called WebZinc to help parse web pages in VB.net. I am trying to use a particular method following the example in the help reference but am unable to get VB.net to...
2
by: danthman | last post by:
Can someone tell me why the following VB.NET code doesn't work? ----- Imports System.Data.SqlClient Partial Class PageHeader Inherits System.Web.UI.UserControl Public ConnectionObjG As...
7
by: pcnerd | last post by:
In Java I can use, for example, " Imports java.util.* ". Can I use, for example, " Imports System.* " instead of several different "Imports" statements? Thank you. David
1
by: Terry Olsen | last post by:
I have written a class library that I want to reference from a windows app. The filename is UPSTrackTool.dll. The Class name is UPSTrackTool. When I reference it from my windows app, I put the...
4
by: BillE | last post by:
Does a subclass have to import namespaces which were already imported by the superclass? I have a base class which imports the System.Data.SQLClient namespace to use the dataset member. When...
1
by: Alexander Eisenhuth | last post by:
Hi, PyLint says that "Relative imports" ... are worth to be warned . And I ask myself why? ----------------- Example directory structure --------- Sound/ Top-level package...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.