How to create array class?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RGFuaWVs?=

    #1

    How to create array class?

    Hi,

    I have create a class name employee.
    Next, i would like to create array for the employee class.
    The code as below:
    dim eply(5) as employee

    when i call eply(0).name="K hrish", an error message prompt out as saying
    object reference is null...

    Any idea to solve it?
    Please advice.
    thank you in advance.

    Rgrds,
    GL
  • igor

    #2
    Re: How to create array class?

    try this:

    dim eply(5) as employee
    eply(0)=new employee
    eply(0).name="K hrish"


    Daniel wrote:
    Hi,
    >
    I have create a class name employee.
    Next, i would like to create array for the employee class.
    The code as below:
    dim eply(5) as employee
    >
    when i call eply(0).name="K hrish", an error message prompt out as saying
    object reference is null...
    >
    Any idea to solve it?
    Please advice.
    thank you in advance.
    >
    Rgrds,
    GL

    Comment

    • Tom Shelton

      #3
      Re: How to create array class?

      On 2007-01-07, Daniel <Daniel@discuss ions.microsoft. comwrote:
      Hi,
      >
      I have create a class name employee.
      Next, i would like to create array for the employee class.
      The code as below:
      dim eply(5) as employee
      >
      when i call eply(0).name="K hrish", an error message prompt out as saying
      object reference is null...
      >
      Any idea to solve it?
      Please advice.
      thank you in advance.
      >
      Rgrds,
      GL
      Dim eply() As Employee { _
      new Employee(), _
      new Employee(), _
      new Employee(), _
      new Employee(), _
      new Employee()}

      --
      Tom Shelton

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: How to create array class?

        Daniel,

        For 2005



        I hope this helps,

        Cor


        Comment

        • =?Utf-8?B?RGFuaWVs?=

          #5
          Re: How to create array class?

          Hi all,

          thanks for your response.
          I managed to solve the "object reference to null..." error message,however ,
          another issue appears.

          I cannot get the list of 5 different records to be updated into the class
          arrays, for instance:

          inputs:
          eply(0).name="K rish"
          eply(1).name="J ames"
          eply(2).name="B ond"

          outputs:
          all display as "Bond" name which is the last record during updating.

          In my class, my code as follow:
          public shared sname as string

          Public Shared Property name() As String
          Get
          Return sname
          End Get
          Set(ByVal Value As String)
          sname = Value
          End Set
          End Property

          Any advice, please.

          thank you in advance.

          Rgrds,
          GL


          "Cor Ligthert [MVP]" wrote:

          Comment

          • RobinS

            #6
            Re: How to create array class?

            How are you displaying them?

            Robin S.
            =============== =========
            "Daniel" <Daniel@discuss ions.microsoft. comwrote in message
            news:DB4E9F2F-9C1A-49E6-9088-E5F900F7FB83@mi crosoft.com...
            Hi all,
            >
            thanks for your response.
            I managed to solve the "object reference to null..." error
            message,however ,
            another issue appears.
            >
            I cannot get the list of 5 different records to be updated into the
            class
            arrays, for instance:
            >
            inputs:
            eply(0).name="K rish"
            eply(1).name="J ames"
            eply(2).name="B ond"
            >
            outputs:
            all display as "Bond" name which is the last record during updating.
            >
            In my class, my code as follow:
            public shared sname as string
            >
            Public Shared Property name() As String
            Get
            Return sname
            End Get
            Set(ByVal Value As String)
            sname = Value
            End Set
            End Property
            >
            Any advice, please.
            >
            thank you in advance.
            >
            Rgrds,
            GL
            >
            >
            "Cor Ligthert [MVP]" wrote:
            >
            >Daniel,
            >>
            >For 2005
            >>
            >http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846
            >>
            >I hope this helps,
            >>
            >Cor
            >>
            >>
            >>

            Comment

            • Stephany Young

              #7
              Re: How to create array class?

              Tom Shelton showed you how to create an array of 5 with 5 elements and
              initialize each element to a seperate instance of an Employee object.

              It is clear, however, that you have created one instance of an Employee
              object and assigned it to all 5 elements of the array. This will cause the
              exact symptons you are observing.


              "Daniel" <Daniel@discuss ions.microsoft. comwrote in message
              news:DB4E9F2F-9C1A-49E6-9088-E5F900F7FB83@mi crosoft.com...
              Hi all,
              >
              thanks for your response.
              I managed to solve the "object reference to null..." error
              message,however ,
              another issue appears.
              >
              I cannot get the list of 5 different records to be updated into the class
              arrays, for instance:
              >
              inputs:
              eply(0).name="K rish"
              eply(1).name="J ames"
              eply(2).name="B ond"
              >
              outputs:
              all display as "Bond" name which is the last record during updating.
              >
              In my class, my code as follow:
              public shared sname as string
              >
              Public Shared Property name() As String
              Get
              Return sname
              End Get
              Set(ByVal Value As String)
              sname = Value
              End Set
              End Property
              >
              Any advice, please.
              >
              thank you in advance.
              >
              Rgrds,
              GL
              >
              >
              "Cor Ligthert [MVP]" wrote:
              >
              >Daniel,
              >>
              >For 2005
              >>
              >http://www.vb-tips.com/dbpages.aspx?...b-9d0a3cf01846
              >>
              >I hope this helps,
              >>
              >Cor
              >>
              >>
              >>

              Comment

              • _AnonCoward

                #8
                Re: How to create array class?


                "Daniel" <Daniel@discuss ions.microsoft. comwrote in message
                news:DB4E9F2F-9C1A-49E6-9088-E5F900F7FB83@mi crosoft.com...
                : Hi all,
                :
                : thanks for your response.
                : I managed to solve the "object reference to null..." error
                message,however ,
                : another issue appears.
                :
                : I cannot get the list of 5 different records to be updated into the
                class
                : arrays, for instance:
                :
                : inputs:
                : eply(0).name="K rish"
                : eply(1).name="J ames"
                : eply(2).name="B ond"
                :
                : outputs:
                : all display as "Bond" name which is the last record during updating.
                :
                : In my class, my code as follow:
                : public shared sname as string
                :
                : Public Shared Property name() As String
                : Get
                : Return sname
                : End Get
                : Set(ByVal Value As String)
                : sname = Value
                : End Set
                : End Property
                :
                : Any advice, please.
                :
                : thank you in advance.
                :
                : Rgrds,
                : GL
                :
                :
                : "Cor Ligthert [MVP]" wrote:
                :
                : Daniel,
                : >
                : For 2005
                : >
                : >

                : >
                : I hope this helps,
                : >
                : Cor
                : >
                : >
                : >


                Comment

                • _AnonCoward

                  #9
                  Re: How to create array class?


                  "Daniel" <Daniel@discuss ions.microsoft. comwrote in message
                  news:DB4E9F2F-9C1A-49E6-9088-E5F900F7FB83@mi crosoft.com...
                  : Hi all,
                  :
                  : thanks for your response.
                  : I managed to solve the "object reference to null..." error
                  : message,however , another issue appears.
                  :
                  : I cannot get the list of 5 different records to be updated into the
                  : class arrays, for instance:
                  :
                  : inputs:
                  : eply(0).name="K rish"
                  : eply(1).name="J ames"
                  : eply(2).name="B ond"
                  :
                  : outputs:
                  : all display as "Bond" name which is the last record during updating.
                  :
                  : In my class, my code as follow:
                  : public shared sname as string
                  :
                  : Public Shared Property name() As String
                  : Get
                  : Return sname
                  : End Get
                  : Set(ByVal Value As String)
                  : sname = Value
                  : End Set
                  : End Property
                  :
                  : Any advice, please.
                  :
                  : thank you in advance.


                  Sorry for the earlier response. I fat fingered and inadvetantly sent
                  the post. Oops...


                  Anyway, your name variable (sName) is Shared which means there is only
                  one copy of it. When each object's name property is being set, they
                  are all setting the value of the same variable. Try removing the
                  Shared keyword.


                  Ralf
                  --
                  --
                  ----------------------------------------------------------
                  * ^~^ ^~^ *
                  * _ {~ ~} {~ ~} _ *
                  * /_``>*< >*<''_\ *
                  * (\--_)++) (++(_--/) *
                  ----------------------------------------------------------
                  There are no advanced students in Aikido - there are only
                  competent beginners. There are no advanced techniques -
                  only the correct application of basic principles.



                  Comment

                  • =?Utf-8?B?RGFuaWVs?=

                    #10
                    Re: How to create array class?

                    Hi all,

                    thanks for the help.
                    Finally, _AnonCoward has identified the root cause which i almost forget
                    :shared syntax.

                    Thanks for all the help given.

                    Rgrds,
                    GL

                    "_AnonCowar d" wrote:
                    >
                    "Daniel" <Daniel@discuss ions.microsoft. comwrote in message
                    news:DB4E9F2F-9C1A-49E6-9088-E5F900F7FB83@mi crosoft.com...
                    : Hi all,
                    :
                    : thanks for your response.
                    : I managed to solve the "object reference to null..." error
                    : message,however , another issue appears.
                    :
                    : I cannot get the list of 5 different records to be updated into the
                    : class arrays, for instance:
                    :
                    : inputs:
                    : eply(0).name="K rish"
                    : eply(1).name="J ames"
                    : eply(2).name="B ond"
                    :
                    : outputs:
                    : all display as "Bond" name which is the last record during updating.
                    :
                    : In my class, my code as follow:
                    : public shared sname as string
                    :
                    : Public Shared Property name() As String
                    : Get
                    : Return sname
                    : End Get
                    : Set(ByVal Value As String)
                    : sname = Value
                    : End Set
                    : End Property
                    :
                    : Any advice, please.
                    :
                    : thank you in advance.
                    >
                    >
                    Sorry for the earlier response. I fat fingered and inadvetantly sent
                    the post. Oops...
                    >
                    >
                    Anyway, your name variable (sName) is Shared which means there is only
                    one copy of it. When each object's name property is being set, they
                    are all setting the value of the same variable. Try removing the
                    Shared keyword.
                    >
                    >
                    Ralf
                    --
                    --
                    ----------------------------------------------------------
                    * ^~^ ^~^ *
                    * _ {~ ~} {~ ~} _ *
                    * /_``>*< >*<''_\ *
                    * (\--_)++) (++(_--/) *
                    ----------------------------------------------------------
                    There are no advanced students in Aikido - there are only
                    competent beginners. There are no advanced techniques -
                    only the correct application of basic principles.
                    >
                    >
                    >
                    >

                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: How to create array class?

                      Daniel,

                      I think that you make not only me curious, what has shared/instanced to do
                      with the by you described problem. It is obvious that your (new made) class
                      has no indexer, that has nothing to do with instanced or shared?

                      Cor


                      Comment

                      • Tom Shelton

                        #12
                        Re: How to create array class?

                        On 2007-01-08, Cor Ligthert [MVP] <notmyfirstname @planet.nlwrote :
                        Daniel,
                        >
                        I think that you make not only me curious, what has shared/instanced to do
                        with the by you described problem. It is obvious that your (new made) class
                        has no indexer, that has nothing to do with instanced or shared?
                        >
                        Cor
                        Cor,


                        He had the name property of his class defined as shared - so, setting it in
                        one instance set it for all....

                        --
                        Tom Shelton

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: How to create array class?

                          Tom,

                          That he wrote, but how he did that, it can by handy

                          Something like this?

                          static x as string = "Tom"
                          dim y(5) as string = x

                          Can be very efficient but I don't know it.

                          Cor

                          "Tom Shelton" <tom_shelton@co mcastXXXXXXX.ne tschreef in bericht
                          news:1ZSdnXLBao Aokz7YnZ2dnUVZ_ sbinZ2d@comcast .com...
                          On 2007-01-08, Cor Ligthert [MVP] <notmyfirstname @planet.nlwrote :
                          >Daniel,
                          >>
                          >I think that you make not only me curious, what has shared/instanced to
                          >do
                          >with the by you described problem. It is obvious that your (new made)
                          >class
                          >has no indexer, that has nothing to do with instanced or shared?
                          >>
                          >Cor
                          >
                          Cor,
                          >
                          >
                          He had the name property of his class defined as shared - so, setting it
                          in
                          one instance set it for all....
                          >
                          --
                          Tom Shelton

                          Comment

                          Working...