variable declaration ?

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

    #1

    variable declaration ?

    hi,

    what does the following statement mean and what does it do?

    Dim obTest As Record.Class1 =
    CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt), Record.Class1)

    GetSessionInfo( ) simply does this Return Me.Session(name )

    TestConstant is a contstant containing "test.teste r"

    What does me.session(name ) do?

    Also, since class1 has many methods, about 10 properties, and 2 collections
    does this assign structure of properties to obTest?

    Thanks a lot.



  • Linda Liu [MSFT]

    #2
    RE: variable declaration ?

    Hi,

    Thank you for posting.

    It's hard for me to explain the statement at this point. Would you please
    show me the whole related code including the definition of Class1, Class2
    and Class3?

    I look forward to your reply.

    Sincerely,
    Linda Liu
    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.
    =============== =============== =============== =======

    Comment

    • GhostInAK

      #3
      Re: variable declaration ?

      Hello RJ,

      Simple... Let's break it down.

      Dim obTest As Record.Class1 ' This creates a variable named obTest with
      a data type of Record.Class1
      the = sign in a Dim statement means that the right side of the expression
      will be used to initialize the variable

      CType converts parameter1 into a variable of datatype parameter2... So:
      Class2.GetSessi onInfo(class3.T estConstant) gets converted into a Record.Class1..
      which then gets assigned to obTest.

      Simple eh.

      -Boo
      [color=blue]
      > hi,
      >
      > what does the following statement mean and what does it do?
      >
      > Dim obTest As Record.Class1 =
      > CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt), Record.Class1)
      >
      > GetSessionInfo( ) simply does this Return Me.Session(name )
      >
      > TestConstant is a contstant containing "test.teste r"
      >
      > What does me.session(name ) do?
      >
      > Also, since class1 has many methods, about 10 properties, and 2
      > collections does this assign structure of properties to obTest?
      >
      > Thanks a lot.
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: variable declaration ?

        RJ,

        See inline[color=blue]
        >
        > Dim obTest As Record.Class1 =
        > CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt), Record.Class1)[/color]

        This means that you create an Object obTest, that holds the reference to the
        object Class2.GetSessi onInfo(class3.T estConstant).

        You can use that obTest object now direct without everytime to use that long
        description.
        (The word DirectCast instead of CType (convert type) would here probably be
        better)
        [color=blue]
        >
        > GetSessionInfo( ) simply does this Return Me.Session(name )
        >[/color]
        I don't see this on MSDN, which means that it is a method in your program
        (class)
        [color=blue]
        > TestConstant is a contstant containing "test.teste r"
        >
        > What does me.session(name ) do?
        >[/color]

        A session is a temporaly storage used to holds data between send and
        postback from webpages.
        [color=blue]
        > Also, since class1 has many methods, about 10 properties, and 2
        > collections does this assign structure of properties to obTest?
        >[/color]
        The difference between a Class and a structure is the place where it is in
        memory. A structure is always direct in your mainprogram on the main heap an
        therefore inefficient. A class is on the managed heap, and can be destroyed
        (is automaticly done by the managed code) when not needed anymore/

        Therefore if something is in a class, than it is in the class and not in a
        structure. (Although a class can reference to a structure).

        I hope this helps,

        Cor


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: variable declaration ?

          typing error,

          Main heap has to be Main stack, my thought was already something further in
          the message.

          Cor

          "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schreef in bericht
          news:%23lcr2Wol GHA.4164@TK2MSF TNGP03.phx.gbl. ..[color=blue]
          > RJ,
          >
          > See inline[color=green]
          >>
          >> Dim obTest As Record.Class1 =
          >> CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt), Record.Class1)[/color]
          >
          > This means that you create an Object obTest, that holds the reference to
          > the object Class2.GetSessi onInfo(class3.T estConstant).
          >
          > You can use that obTest object now direct without everytime to use that
          > long description.
          > (The word DirectCast instead of CType (convert type) would here probably
          > be better)
          >[color=green]
          >>
          >> GetSessionInfo( ) simply does this Return Me.Session(name )
          >>[/color]
          > I don't see this on MSDN, which means that it is a method in your program
          > (class)
          >[color=green]
          >> TestConstant is a contstant containing "test.teste r"
          >>
          >> What does me.session(name ) do?
          >>[/color]
          >
          > A session is a temporaly storage used to holds data between send and
          > postback from webpages.
          >[color=green]
          >> Also, since class1 has many methods, about 10 properties, and 2
          >> collections does this assign structure of properties to obTest?
          >>[/color]
          > The difference between a Class and a structure is the place where it is in
          > memory. A structure is always direct in your mainprogram on the main heap
          > an therefore inefficient. A class is on the managed heap, and can be
          > destroyed (is automaticly done by the managed code) when not needed
          > anymore/
          >
          > Therefore if something is in a class, than it is in the class and not in a
          > structure. (Although a class can reference to a structure).
          >
          > I hope this helps,
          >
          > Cor
          >
          >[/color]


          Comment

          • rJ

            #6
            Re: variable declaration ?

            First of all...thank you all for your responses. It is greatly appreciated.
            [color=blue][color=green]
            >> GetSessionInfo( ) simply does this Return Me.Session(name )
            >>
            >>I don't see this on MSDN, which means that it is a method in your program
            >>(class)[/color][/color]

            It is a method in my code that contains only
            Return Me.Session(name )

            The value of class3.TestCons tant is "test.teste r" at run time according to
            debug. I see where the constant is assigned in class3. So at run time
            Class2.GetSessi onInfo(class3.T estConstant) is equal to "test.teste r" so
            statement would then be
            CType("test.tes ter", Record.Class1).

            How is "test.test" being returned as Record.Class1?

            I just don't get what CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt),
            Record.Class1) is doing and why you would want to do this? :(

            Why not just stop at
            Dim obTest As Record.Class1

            Why is the initial value being set to
            CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt), Record.Class1)

            Finally, why don't we have to have New keyword behind as in variable
            declaration? I have searched entire project and don't find a Dim obTest as
            New Record.Class1.

            Thanks again for your patience and assistance.

            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
            news:%23lcr2Wol GHA.4164@TK2MSF TNGP03.phx.gbl. ..[color=blue]
            > RJ,
            >
            > See inline[color=green]
            >>
            >> Dim obTest As Record.Class1 =
            >> CType(Class2.Ge tSessionInfo(cl ass3.TestConsta nt), Record.Class1)[/color]
            >
            > This means that you create an Object obTest, that holds the reference to
            > the object Class2.GetSessi onInfo(class3.T estConstant).
            >
            > You can use that obTest object now direct without everytime to use that
            > long description.
            > (The word DirectCast instead of CType (convert type) would here probably
            > be better)
            >[color=green]
            >>
            >> GetSessionInfo( ) simply does this Return Me.Session(name )
            >>[/color]
            > I don't see this on MSDN, which means that it is a method in your program
            > (class)
            >[color=green]
            >> TestConstant is a contstant containing "test.teste r"
            >>
            >> What does me.session(name ) do?
            >>[/color]
            >
            > A session is a temporaly storage used to holds data between send and
            > postback from webpages.
            >[color=green]
            >> Also, since class1 has many methods, about 10 properties, and 2
            >> collections does this assign structure of properties to obTest?
            >>[/color]
            > The difference between a Class and a structure is the place where it is in
            > memory. A structure is always direct in your mainprogram on the main heap
            > an therefore inefficient. A class is on the managed heap, and can be
            > destroyed (is automaticly done by the managed code) when not needed
            > anymore/
            >
            > Therefore if something is in a class, than it is in the class and not in a
            > structure. (Although a class can reference to a structure).
            >
            > I hope this helps,
            >
            > Cor
            >
            >[/color]


            Comment

            • Linda Liu [MSFT]

              #7
              Re: variable declaration ?

              Hi Rj,

              Thank you for your update.

              It seems that the expression "Class2.GetSess ionInfo(class3. TestContant)"
              returns a object of type Record.Class1. You can assign this returned object
              to the variable obTest and needn't use New keyword.

              Although the value of class3.TestCons tant is "test.teste r" at run time,
              Class2.GetSessi onInfo(class3.T estConstant) should not be equal to
              "test.teste r". It should be equal to the value of the expression of
              "Me.Session(nam e)".

              I think the core of the problem is the expression "Me.Session(nam e)", which
              is not clear to us until now. In order to explain this expression, would
              you please show us the entire related code?

              I look forward to your reply.

              Sincerely,
              Linda Liu
              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.
              =============== =============== =============== =======

              Comment

              Working...