Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. About Public Arrays in VB

About Public Arrays in VB

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structureshelptutorialquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Niungareamit
    wrote on last edited by
    #1

    hi.. I m working in VB in Visual Studion .Net. In my project I have two forms. I m declaring a public array in form1 which i want to use in 2nd form (form2) also. On form1 i have a button which when clicked form2 will be shown. I want that contents of array in form1 should be acessible in form2 also. But i m facing the problem that how to open form2 on button click in form1 and use array of form1 in form2. So, Is there any solution for this???

    W R 2 Replies Last reply
    0
    • N Niungareamit

      hi.. I m working in VB in Visual Studion .Net. In my project I have two forms. I m declaring a public array in form1 which i want to use in 2nd form (form2) also. On form1 i have a button which when clicked form2 will be shown. I want that contents of array in form1 should be acessible in form2 also. But i m facing the problem that how to open form2 on button click in form1 and use array of form1 in form2. So, Is there any solution for this???

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      If the array is declared as public then all you need to do is preface the call to the array with form1 i.e textbox1.text = form1.myarray(0)

      1 Reply Last reply
      0
      • N Niungareamit

        hi.. I m working in VB in Visual Studion .Net. In my project I have two forms. I m declaring a public array in form1 which i want to use in 2nd form (form2) also. On form1 i have a button which when clicked form2 will be shown. I want that contents of array in form1 should be acessible in form2 also. But i m facing the problem that how to open form2 on button click in form1 and use array of form1 in form2. So, Is there any solution for this???

        R Offline
        R Offline
        Ray Cassick
        wrote on last edited by
        #3

        Personally this is a very BAD idea. Forms are objects that should encapsulate the data within them. At no time should one object just simply reach out and grab hold of data inside of another object. This is really one of the major tenets of OOP design. That does not mean that you can't talk between forms, but it should be done properly via an established interface. You should be providing an interface (functions, methods, or custom properties) on your forms for allow that type of communication to happen. This gives you a way to not only gain access between data on forms the proper OOP way, but also gives you the ability to provide data validation, authentication when needed, and also perhaps some contention detection when that may be needed also. Please, NO public variables on forms! Forms are objects just like a class is. You don't open up a variable inside a class by making it public, you provide an accessor method to get to it. RIGHT? That's how you are doing in in your classes? Please say yes? Forms are no different.


        LinkedIn[^] | Blog[^] | Twitter[^]

        I 1 Reply Last reply
        0
        • R Ray Cassick

          Personally this is a very BAD idea. Forms are objects that should encapsulate the data within them. At no time should one object just simply reach out and grab hold of data inside of another object. This is really one of the major tenets of OOP design. That does not mean that you can't talk between forms, but it should be done properly via an established interface. You should be providing an interface (functions, methods, or custom properties) on your forms for allow that type of communication to happen. This gives you a way to not only gain access between data on forms the proper OOP way, but also gives you the ability to provide data validation, authentication when needed, and also perhaps some contention detection when that may be needed also. Please, NO public variables on forms! Forms are objects just like a class is. You don't open up a variable inside a class by making it public, you provide an accessor method to get to it. RIGHT? That's how you are doing in in your classes? Please say yes? Forms are no different.


          LinkedIn[^] | Blog[^] | Twitter[^]

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #4

          What!? I just use Option PublicEverything so I don't have to think! All kidding aside, though, Ray is right. Just need to make a public accessor for the array, and all is well.

          Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

          M 1 Reply Last reply
          0
          • I Ian Shlasko

            What!? I just use Option PublicEverything so I don't have to think! All kidding aside, though, Ray is right. Just need to make a public accessor for the array, and all is well.

            Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

            M Offline
            M Offline
            MikeMarq
            wrote on last edited by
            #5

            Actually I think he might be better to just use a seperate module for his public data. The forms should only contain data that is very specific to that particular form (which usually means it doesn't need to be public). Everything else such as functionality should be in modules or classes.

            R 1 Reply Last reply
            0
            • M MikeMarq

              Actually I think he might be better to just use a seperate module for his public data. The forms should only contain data that is very specific to that particular form (which usually means it doesn't need to be public). Everything else such as functionality should be in modules or classes.

              R Offline
              R Offline
              Ray Cassick
              wrote on last edited by
              #6

              I can agree there, but then you still should not just reach out form the form and access the public object. It should be passed to the form upon creation via the forms constructor. NOTHING in my opinion should be simply accessible via being public.


              LinkedIn[^] | Blog[^] | Twitter[^]

              W 1 Reply Last reply
              0
              • R Ray Cassick

                I can agree there, but then you still should not just reach out form the form and access the public object. It should be passed to the form upon creation via the forms constructor. NOTHING in my opinion should be simply accessible via being public.


                LinkedIn[^] | Blog[^] | Twitter[^]

                W Offline
                W Offline
                Wayne Gaylard
                wrote on last edited by
                #7

                My Apologies. Of course you are right. You should implement public properties rather than declaring variables Public in any Class. My Bad. :-O

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups