Type xxx not defined #2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chaz

    #1

    Type xxx not defined #2

    Hi,
    * this class is defined in assembly XXXXClsLib :
    Public class VVDB : inherits DBFuncs
    ...
    * Assembly YYYYFwApi has a reference to XXXXClsLib
    * this class B in YYYYFwApi has an imports stmt :
    imports XXXXClsLib.VVDB

    * and this code of class b gives an error
    Private Function zzz() As String

    Dim myvvdb as new VVDB <<- VVDB not defined

    and an error correction via shift+alt+f10

    says use XXXXClsLib.VVDB

    well why is that ?

    also if I change the imports to

    imports VVDB = XXXXClsLib.VVDB

    then all is well.

    why is that ?

    thanks for explanation



  • ssta

    #2
    Re: Type xxx not defined #2

    Try: Imports XXXXClsLib
    Instead of: imports XXXXClsLib.VVDB
    chaz wrote:[color=blue]
    > Hi,
    > * this class is defined in assembly XXXXClsLib :
    > Public class VVDB : inherits DBFuncs
    > ...
    > * Assembly YYYYFwApi has a reference to XXXXClsLib
    > * this class B in YYYYFwApi has an imports stmt :
    > imports XXXXClsLib.VVDB
    >
    > * and this code of class b gives an error
    > Private Function zzz() As String
    >
    > Dim myvvdb as new VVDB <<- VVDB not defined
    >
    > and an error correction via shift+alt+f10
    >
    > says use XXXXClsLib.VVDB
    >
    > well why is that ?
    >
    > also if I change the imports to
    >
    > imports VVDB = XXXXClsLib.VVDB
    >
    > then all is well.
    >
    > why is that ?
    >
    > thanks for explanation[/color]

    Comment

    • chaz

      #3
      Re: Type xxx not defined #2

      yeah that works as well, but why? I have another class in the same assembly
      wich requires XXXClsLib.class name in the imports stmt else it's undefined .
      Am I missing some underlying concept or is it just try until it works?

      thanks


      "ssta" wrote:
      [color=blue]
      > Try: Imports XXXXClsLib
      > Instead of: imports XXXXClsLib.VVDB
      > chaz wrote:[color=green]
      > > Hi,
      > > * this class is defined in assembly XXXXClsLib :
      > > Public class VVDB : inherits DBFuncs
      > > ...
      > > * Assembly YYYYFwApi has a reference to XXXXClsLib
      > > * this class B in YYYYFwApi has an imports stmt :
      > > imports XXXXClsLib.VVDB
      > >
      > > * and this code of class b gives an error
      > > Private Function zzz() As String
      > >
      > > Dim myvvdb as new VVDB <<- VVDB not defined
      > >
      > > and an error correction via shift+alt+f10
      > >
      > > says use XXXXClsLib.VVDB
      > >
      > > well why is that ?
      > >
      > > also if I change the imports to
      > >
      > > imports VVDB = XXXXClsLib.VVDB
      > >
      > > then all is well.
      > >
      > > why is that ?
      > >
      > > thanks for explanation[/color]
      >
      >[/color]

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Type xxx not defined #2

        Chaz,

        In addition to ssta
        [color=blue]
        > says use XXXXClsLib.VVDB
        >[/color]
        Than it is not using the import, you have described the full path.

        Cor



        Comment

        • Jeffrey Tan[MSFT]

          #5
          Re: Type xxx not defined #2

          Hi Chaz,

          Thanks for your post!

          I assume VVDB is a class name not a namespace name.

          In VB.net syntax, there are 2 types of "Imports" statement: "Imports Alias"
          and "Namespace Imports".
          1. An import alias defines an alias for a namespace or type
          2. A namespace import imports all of the members of a namespace or type,
          allowing the identifier of each member of the namespace or type to be used
          without qualification.

          In your scenario, you are using "Namespace Imports" to eliminate the
          namespace qualification of "VVDB" class, so you should "Imports" the
          namespace of "VVDB" class instead of "Imports" this class itself. Let's
          take another example: to use FileStream class in System.IO namespace, we
          should import System.IO namespace instead of System.IO.FileS tream itself.
          If we import System.IO.FileS tream itself, the compiler still can not see
          FileStream class, because FileStream class is not declared under
          System.IO.FileS tream, but System.IO.

          Imports System.IO.FileS tream
          Public Class Form1
          Inherits System.Windows. Forms.Form

          Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          Dim fs As New FileStream '<<this statement generates compile time
          error
          End Sub
          End Class

          Why does "imports VVDB = XXXXClsLib.VVDB " eliminate the compile error? This
          "imports" applies to "Imports Alias", not "Namespace Imports". By doing
          this, you are saying VVDB is an alias of XXXXClsLib.VVDB class, so in
          compile time, the compiler will automatically substitute your typed "VVDB"
          with "XXXXClsLib.VVD B" class.

          Hope this explanation makes things clear.

          Best regards,
          Jeffrey Tan
          Microsoft Online Community Support
          =============== =============== =============== =====
          When responding to posts, please "Reply to Group" via your newsreader so
          that others may learn and benefit from your issue.
          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          • Jeffrey Tan[MSFT]

            #6
            Re: Type xxx not defined #2

            Below is the VB.net specification regarding "Import Aliases" and
            "6.3.1 Import Aliases"
            http://msdn.microsoft.com/library/de...us/vbls7/html/
            vblrfVBSpec5_2_ 1.asp
            "6.3.2 Namespace Imports"
            http://msdn.microsoft.com/library/de...us/vbls7/html/
            vblrfVBSpec5_2_ 2.asp

            For your information.

            Best regards,
            Jeffrey Tan
            Microsoft Online Community Support
            =============== =============== =============== =====
            When responding to posts, please "Reply to Group" via your newsreader so
            that others may learn and benefit from your issue.
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no rights.

            Comment

            • chaz

              #7
              Re: Type xxx not defined #2

              Hi Jeffrey,
              Here is where I got confused (and still am)


              Assembly A has to classes

              public class VVDB
              public function vvx()

              public class ASPutility

              public shared function Aspfunc() as object <<= note shared

              Assembly B has theses two imports

              imports A.Asputility
              imports A

              the 2nd is so we can write
              Dim vvdb as new VVDB
              instead of
              Dim vvdb as new A.VVDB
              (which has been discussed )

              but the first is so we can write
              xxx = AspFunc

              instead of
              xxx = A.AspFunc



              ""Jeffrey Tan[MSFT]"" wrote:
              [color=blue]
              > Below is the VB.net specification regarding "Import Aliases" and
              > "6.3.1 Import Aliases"
              > http://msdn.microsoft.com/library/de...us/vbls7/html/
              > vblrfVBSpec5_2_ 1.asp
              > "6.3.2 Namespace Imports"
              > http://msdn.microsoft.com/library/de...us/vbls7/html/
              > vblrfVBSpec5_2_ 2.asp
              >
              > For your information.
              >
              > Best regards,
              > Jeffrey Tan
              > Microsoft Online Community Support
              > =============== =============== =============== =====
              > When responding to posts, please "Reply to Group" via your newsreader so
              > that others may learn and benefit from your issue.
              > =============== =============== =============== =====
              > This posting is provided "AS IS" with no warranties, and confers no rights.
              >
              >[/color]

              Comment

              • Jeffrey Tan[MSFT]

                #8
                Re: Type xxx not defined #2

                Hi Scott,

                Thanks for your feedback!

                Yes, this condition falls in the "Namespace Imports" syntax of VB.net. As
                you can see in "6.3.2 Namespace Imports", a namespace imports can not only
                import a namespace, can it also import a type(class):
                "In the case of types, a namespace import only allows access to the shared
                members of the type without requiring qualification of the class name. "

                This explains why you can eliminate the usage of class name in front of the
                shared method.

                Additionally, if you are curious, based on my test, the C# "using"
                statement(which is the counterpoint to "imports" statement) does not
                support this feature. "using" statement can only import the namespace, it
                can not be used to import the class/type.

                Hope this helps!

                Best regards,
                Jeffrey Tan
                Microsoft Online Community Support
                =============== =============== =============== =====
                When responding to posts, please "Reply to Group" via your newsreader so
                that others may learn and benefit from your issue.
                =============== =============== =============== =====
                This posting is provided "AS IS" with no warranties, and confers no rights.

                Comment

                Working...