Results 1 to 5 of 5

Thread: [RESOLVED] Can you Alias a Project level Imports statement?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    85

    Resolved [RESOLVED] Can you Alias a Project level Imports statement?

    I know you can alias an Imports statement in code:
    Code:
    Imports xyz = ProjectABC.ClassABC
    But if I want to use the Project Properties, Reference tab to select a namespace to allow a project-wide setting, is it possible to alias that namespace?

    Thanks!

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Can you Alias a Project level Imports statement?

    huh? o.O ???? I don't follow...

    wait, you mean you want to alias namespaces of referenced assemblies? the imports doesn't care where the assembly is... you can alias any namespace you want.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    85

    Re: Can you Alias a Project level Imports statement?

    techgnome, say I have a form and in that form I do the imports:
    Code:
    Imports xyz = ProjectABC.ClassABC
    ...
    Dim userName as String = xyz.UserName
    Now, if I have form 2 I can't do this:
    Code:
    Dim userName as String = xyz.userName
    without declaring another Imports statement.
    I know you can do import at the project level as I mentioned in my first post but that doesn't appear to allow you to alias the imported namespace. So the above line of code would become
    Code:
    Dim userName as String = SomeName.ClassName.UserName
    and I'd have to use that fully qualified name everyplace I needed the reference, when all I want to use is xyz.userName

    Does that make more sense?

    (Edit: I might add that I WANT some kind of qualifier so that when reading the code you know where the member reference originates. I just don't want the full name)

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

    Re: Can you Alias a Project level Imports statement?

    The bottom half of the References page of the project properties has a text box above the list of namespaces. You just type your aliased import, i.e. xyz = ProjectABC.ClassABC, into that box and then click the Add button beside it.
    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    85

    Re: Can you Alias a Project level Imports statement?

    Thanks jmc, that actually rang a bell when I read your message so I think I encountered that tip somewhere else in the past.

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