473,799 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I use an asterisk in the "Imports" statement?

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
Jul 4 '06 #1
7 2029
No (I found the answer by trying).

Check http://msdn2.microsoft.com/en-us/library/7f38zh8x.aspx for details
(looks like this is necessarily the full qualified name).

--
Patrice

"pcnerd" <pc****@discuss ions.microsoft. coma écrit dans le message de news:
20************* *************** **...icrosof t.com...
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

Jul 4 '06 #2
"pcnerd" <pc****@discuss ions.microsoft. comschrieb:
In Java I can use, for example, " Imports java.util.* ". Can I use, for
example, " Imports System.* " instead of several different "Imports"
statements?
Simply use 'Imports System'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jul 4 '06 #3

Well, needless to say, I'm confused! One reply is "No, you can't. I tried."
& the other is "Simply use 'Imports System' "!

So, I suppose that if I use "Imports System" , it will probably be a pretty
big file.

I wonder why I've gotten 2 different answers.

Thank you. David

"Herfried K. Wagner [MVP]" wrote:
"pcnerd" <pc****@discuss ions.microsoft. comschrieb:
In Java I can use, for example, " Imports java.util.* ". Can I use, for
example, " Imports System.* " instead of several different "Imports"
statements?

Simply use 'Imports System'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jul 5 '06 #4
The answer is NO

Using 'Imports System' will not give you access to
'System.Data.Sq lClient'
If you just import System, you will only get things in the System
namespace such as 'System.Int32' and 'System.Type' etc.

Jul 5 '06 #5
"Steven Nagy" <le*********@ho tmail.comschrie b:
The answer is NO

Using 'Imports System' will not give you access to
'System.Data.Sq lClient'
If you just import System, you will only get things in the System
namespace such as 'System.Int32' and 'System.Type' etc.
That's true, but it would be rather useless to import all subnamespaces of a
namespace. Importing using the asterisk in Java will import the types
contained in the package, but it won't import other packages.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 5 '06 #6

pcnerd wrote:
So, I suppose that if I use "Imports System" , it will probably be a pretty
big file.
This comment suggests you might have a misconception about Imports in
VB.NET, because it is the same word as a Java keyword. Now, my Java
experience is pretty small, but am I right in thinking that in Java you
want to import only the minimum you need to, because importing actually
does something to the produced executable? Well, in VB.NET, Imports is
*entirely* syntactic sugar - all it does is allow us to use the names
of things from our References without fully qualifying them. As the
docs put it: "Importing does not take the place of setting a reference.
It only removes the need to qualify names that are already available to
your project."

For example, once we reference, say, System.dll, everything in there is
available to us whether we use Imports System or not; all the Imports
line does is allow us to refer to System.Uri as simply 'Uri' in our
code.

Note that many commonly-used namespaces are imported automatically in
newly-created projects, at the project level, so we often don't need
any Imports statements in individual files.
Of course, if you knew all this already, great! :)

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using

Jul 5 '06 #7
pcnerd wrote:
Well, needless to say, I'm confused! One reply is "No, you can't. I tried."
& the other is "Simply use 'Imports System' "!

So, I suppose that if I use "Imports System" , it will probably be a pretty
big file.
The resulting file will be /no bigger/, regardless of how many Imports
statements you use, because the Imports statement doesn't do what you
think it does.

It does NOT give your application "access" to anything it didn't have
before. That's does by adding References to other assemblies and no;
the Referenced assemblies are not compiled into your finished program;
they become run-time dependencies.

Imports /only/ allows you, in your code, to /type less/, as in

(without Imports)
Console.Writeli ne( _
System.Reflecti on.MethodBase.G etCurrentMethod ().Name _
)

or (with Imports)

Imports System.Reflecti on.MethodBase
.. . .
Console.Writeli ne( _
GetCurrentMetho d().Name _
)

When the code gets compiled, the fully qualified names get used
regardless of what you typed, so the size of your executable is unaffected.

HTH,
Phill W.
Jul 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2197
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 C#. However, it's a real hassle that the book has no index, just a table of contents. For example, as early as page 8, the book teaches that C#'s "using" statement is the equivalent of VB.NET's "imports" statement. However, that concept...
2
4247
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 machine. My coworker takes the exact same file, compiles it, and gets errors until he explicitly writes out the function as:
1
1465
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
2116
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 recognize it. The code example is: Dim containsWordA As Boolean = New TextProcessor("my string containing words").ContainsWord("containing") where TextProcessor is the object and ContainsWord is the method. VB.net underlines the TextProcessor...
2
1315
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 SqlConnection = New SqlConnection()
3
2307
by: Chris | last post by:
Hi, 1) In file test.aspx, i put: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %> <%@ import namespace="System.Data"%> <%@ import namespace="System.Data.OleDb"%> .... In file test.aspx.vb, i put:
1
1501
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 Imports UPSTrackTool at the top. But when I call any methods I have to use: UPSTrackTool.UPSTrackTool.MyMethod() How do I name this thing so I only have to Imports UPSTrackTool and then I can just call MyMethod()?
1
1729
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 __init__.py Initialize the sound package Utils/ Subpackage
5
13371
by: kimiraikkonen | last post by:
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...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10485
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.