Results 1 to 6 of 6

Thread: Cannot Import Namespace I Created

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Cannot Import Namespace I Created

    I put this on a file
    highlight Code:
    1. Namespace ias
    2.     Module robust
    3.         <Extension()>
    4.         Public Function getChildNode(ByVal node As mshtml.IHTMLDOMNode, ByVal child As Integer) As mshtml.IHTMLDOMNode
    5.             Return node.childNodes(child)
    6.         End Function
    7.  
    8.         Public hello As Double
    9.     End Module
    10.     Class SomeClass
    11.  
    12.     End Class
    13. End Namespace


    I put this on another file
    Code:
    1. Imports ias

    Got error

    Warning 1 Namespace or type specified in the Imports 'ias' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. \\work\c\business\fromwork\currentprojects\program\library\vb.net\angela.vb 5 9 googlepages


    What the hell does that suppose to mean?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Cannot Import Namespace I Created

    If you don't specify an access level for classes and modules, I believe that they will be Friend by default. This is an example of why you should ALWAYS provide an access level for EVERYTHING. If you specify what it is then you know what it is. If you accept the default then you have to be sure of what the default is. If you want those types to be Public then declare them Public.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Cannot Import Namespace I Created

    Oh I should put public module rather than just module

    Well I put the wrong sample. But I experimented anyway.

    To experiment I create a brand new project and do
    vb.net Code:
    1. Imports somename 'This doesn't work Warning 1   Namespace or type specified in the Imports 'somename' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.    D:\Documents and Settings\Ferdy\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Module1.vb   1   9   ConsoleApplication1
    2. Imports System.Linq 'works fine. I can import all namespace except my own
    3.  
    4. Namespace SomeName
    5.     Public Module hello 'It's public here, even though I am sure friends should work just fine
    6.         Public Sub hello1()
    7.  
    8.         End Sub
    9.     End Module
    10. End Namespace
    11. Public Module Module1
    12.     Sub Main()
    13.         SomeName.hello1() 'This works
    14.     End Sub
    15. End Module

    Same error. I bet I am missing something.

    Looks like I simply don't know how to use name space propery
    Last edited by teguh123; Mar 23rd, 2011 at 05:36 AM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Cannot Import Namespace I Created

    Actually I have figured out what the problem is

    I should do Imports projectname.somename rather than just imports somename

    But that would defeat some important purpose. The same files are in several different projects and I do not want to "know" the project names. I want something that'll work irrelevant of the name of the project is.

    Also I want to use imports because I want to create extension. I guess namespace feature is the one that has to go unless some genius will provide me with some solution.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Cannot Import Namespace I Created

    It's not really the project name specifically. Every project has a root namespace. It is set to the project name by default, but you can change it to whatever you like on the Application page of the project properties. Any type that you don't declare within a Namespace block is a member of the root namespace. Any namespace you declare with a Namespace block is a child of the root namespace.

    There's nothing to stop you using the same root namespace in multiple projects. If you want types in multiple projects to be members of the same namespace then use the same root namespace in each project and, optionally, the same child namespace(s).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Cannot Import Namespace I Created

    Ah I see. What would really be cool is now that I am on the same namespace anyway, I should be able to do

    imports somename

    Yes there is no somename namespace

    What exist is myrootnamespace.somename

    However I do the imports thingy in a file that already is in myrootnamespace.

    I guess that doesn't work out isn't it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width