About Public Arrays in VB
-
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???
-
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???
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)
-
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???
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.
-
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.
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)
-
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)
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.
-
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.
-
My Apologies. Of course you are right. You should implement public properties rather than declaring variables Public in any Class. My Bad. :-O