Declaring an array

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

    Declaring an array

    Where is the correct place to declare an array so that it will be available
    anywhere in the project.

    I have been playing with one form that has two buttons and one listbox. I
    want each button to add a name from an array to the list box.

    Unless I declare the array inside each button_click event, it says the array
    has not been declared.

    Help please,
    Fred


  • Michel Posseth  [MCP]

    #2
    Re: Declaring an array


    Hello Fred
    Where is the correct place to declare an array so that it will be
    available anywhere in the project.
    Well if you want ti to be aviallable everywhere in your whole project i
    would say declare a module ( static class ) and declare your array there as
    Friend or Public
    ( Friend is availlable in your whole Code but only inside your assembly ,
    Public is availlable in your whole Code but also outside your assembly )

    However although above is technicly possible it is bypassing common coding
    guides to code in a more robust self sustainable way
    in the case you describe it should be enough to declare the array at Class
    level .

    And even in the case that you want to use the array in another class (
    object ) you could add a property to that class for your array and thus
    pass it over and back to the next code logic

    regards

    Michel Posseth



    "Fred Blair" <passport@thetr avelintexans.co mschreef in bericht
    news:gfp9jm$v8a $1@news.motzare lla.org...
    Where is the correct place to declare an array so that it will be
    available anywhere in the project.
    >
    I have been playing with one form that has two buttons and one listbox. I
    want each button to add a name from an array to the list box.
    >
    Unless I declare the array inside each button_click event, it says the
    array has not been declared.
    >
    Help please,
    Fred
    >

    Comment

    • Phill W.

      #3
      Re: Declaring an array

      Fred Blair wrote:
      Where is the correct place to declare an array so that it will be available
      anywhere in the project.
      The place to declare an array accessible /anywhere/ in the project in is
      a Module:

      Module Globals
      Public g_values as Integer() = {}
      End Module


      The /correct/ place for your array, though, is private to the Class or
      Module in which it is required and, if required, made additionally
      accessible /outside/ of that class via a Property.

      Class MainForm
      Inherits ... .Form

      Private m_values as Integer() = {}

      [Public|Protecte d|Friend|Privat e] _
      [ReadOnly] _
      Property Values() as Integer()
      Get
      Return m_values
      End Get
      'Set( values as Integer() )
      ' m_values = value
      'End Set
      End Property
      End Class

      Your buttons can access either variable or (better) the Property to
      access the array.

      HTH,
      Phill W.

      Comment

      • Mythran

        #4
        Re: Declaring an array



        "Michel Posseth [MCP]" <MSDN@posseth.c omwrote in message
        news:etcURn$RJH A.3932@TK2MSFTN GP02.phx.gbl...
        >
        Hello Fred
        >
        <snip>
        >
        Well if you want ti to be aviallable everywhere in your whole project i
        would say declare a module ( static class ) and declare your array there
        as Friend or Public
        ( Friend is availlable in your whole Code but only inside your assembly ,
        Public is availlable in your whole Code but also outside your assembly )
        </snip>

        A little wrong there. Friend is available in the same assembly while public
        is outside the assembly ONLY if the containing class is Public. If the
        containing class is Friend (or internal), then the methods within the class
        are only visible within the same assembly as the class itself is only
        visible within the assembly. (although, with reflection you can access them
        either way).

        HTH,
        Mythran


        Comment

        • Michel Posseth  [MCP]

          #5
          Re: Declaring an array

          Mythran,

          You are prooving me wrong by telling the obvious wich i did not claim at
          all
          So there is nothing wrong with my answer , however the person who would code
          as how you describe obviously has no idea of what he/ she is doing ,or are
          you going to surprise me with a valid reasson ?

          With the "logic" that you used i could "proove" everyones answer wrong in
          this group


          regards

          Michel Posseth [MCP]




          "Mythran" <Mythran@commun ity.nospamschre ef in bericht
          news:CC5BE382-3030-48C7-9934-F4D5250DF19D@mi crosoft.com...
          >
          >
          "Michel Posseth [MCP]" <MSDN@posseth.c omwrote in message
          news:etcURn$RJH A.3932@TK2MSFTN GP02.phx.gbl...
          >>
          >Hello Fred
          >>
          >
          <snip>
          >>
          >Well if you want ti to be aviallable everywhere in your whole project i
          >would say declare a module ( static class ) and declare your array there
          >as Friend or Public
          >( Friend is availlable in your whole Code but only inside your assembly ,
          >Public is availlable in your whole Code but also outside your assembly )
          </snip>
          >
          A little wrong there. Friend is available in the same assembly while
          public is outside the assembly ONLY if the containing class is Public. If
          the containing class is Friend (or internal), then the methods within the
          class are only visible within the same assembly as the class itself is
          only visible within the assembly. (although, with reflection you can
          access them either way).
          >
          HTH,
          Mythran
          >
          >

          Comment

          Working...