473,396 Members | 1,779 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,396 software developers and data experts.

Import Class. Not Imports ... ?

Hello,

In the main root of my web site together with my aspx and aspx.vb files
I have the file global.vb.

This file has a class with all the functions which are used in many
aspx.vb files and it is like this:

Imports System
Namespace Global
Public Class Global
Public Shared Sub Function01()
...
End Sub
...
End Class
End Namespace

In my aspx.vb file I am using the function like this:
Global.function01()

It's not working. I know I am missing some declaration but the options I
tried are not working. I tried to place in my aspx.vb "Imports Global".

Thanks,
Miguel

Nov 19 '05 #1
2 1793
You should be getting a message that c:\<path path path>\Global.vb(2):
namespace 'Global' and class 'Global', declared in 'c:\<path path
path>\Global.asax.vb', conflict in namespace '<project name>'.

You can rename your namespace something like GlobalStuff, then change
your imports statement to match. Of course, now your class Global and
the autogenerated class Global will conflict, so you'll have to be
explicit when referring to them, or rename your class as well.

Nov 19 '05 #2
Hi Shapper,

First, you might want to change the name of your namespace and class, as
there is an intrisic class in ASP.Net called "Global" already - hence the
file global.asax. You may be experiencing an ambiguous name reference here,
but you haven't posted your error message, so I can't tell for sure.

The "Imports" statement is a pre-processor statement that allows you to
reference classes and sub-namespaces under a given namespace wihtout having
to type the namespace every time you use it in your code. This can cause an
ambiguous name exception if, for example, you have 2 namespaces with the
same-named class underneath them, and you refer to the class without
refering the namespace in your code. The compiler can't tell which class in
which namespace you're referring to. In your case, as I said, you import
System.Web, and the global.asax file defines a class called "global" that
inherits System.Web.HttpApplication. So, when you refer to
"Global.function1()" the compiler can't tell WHICH Global class you're
referring to.

It is important to understand the difference between namespaces and classes,
and the usage of namespaces. In OOP, you can create a huge number of
classes, such as exist in the CLR. With possibly thousands of classes, it
can become difficult to know when you've given a class the same name as
another one. A namspace is a further identifier for the class, which
references its position in a hierarchy. IOW, a namespace is not a class, but
a container for classes which helps to uniquely identify them.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:Oo**************@TK2MSFTNGP15.phx.gbl...
Hello,

In the main root of my web site together with my aspx and aspx.vb files I
have the file global.vb.

This file has a class with all the functions which are used in many
aspx.vb files and it is like this:

Imports System
Namespace Global
Public Class Global
Public Shared Sub Function01()
...
End Sub
... End Class
End Namespace

In my aspx.vb file I am using the function like this:
Global.function01()

It's not working. I know I am missing some declaration but the options I
tried are not working. I tried to place in my aspx.vb "Imports Global".

Thanks,
Miguel

Nov 19 '05 #3

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

Similar topics

0
by: Stian Sřiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
9
by: Frantisek Fuka | last post by:
This thing keeps bugging me. It's probably some basic misunderstanding on my part but I am stumped. Let's say I have two Python files: file.py and file2.py. Their contents is as follows: ...
9
by: Paul Rubin | last post by:
That's what the Python style guides advise. They don't seem to like def frob(x): import re if re.search('sdfxyz', x): ... instead preferring that you pollute your module's global namespace...
1
by: Chris S. | last post by:
Consider the sample case: ## a.py import d import b b.App() ## b.py from c import C B = 'B'
4
by: MackS | last post by:
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc' def main():
7
by: Lance | last post by:
Is there any way to create an import alias that applies to the entire project? For example, lets say that I want "VB" to represent Microsoft.VisualBasic throughout my entire project. Is there...
0
by: Anders J. Munch | last post by:
Now 2.5 is out, and we have a syntax for explicit relative imports (PEP 328, http://www.python.org/dev/peps/pep-0328/, in case anyone wasn't paying attention). The long-term plan is that the...
5
by: Greg Hoover | last post by:
How does one get access to the class that imported a module. For example: foo imports bar -- how does bar access foo? Thanks.
2
by: Bill Jackson | last post by:
Once again, I am having issues with imports... Until now, I thought the general guidelines were to rarely use 'from x import y' syntax, except when you really want to copy names over. However, I...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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.