|
-
Aug 8th, 2012, 12:46 AM
#1
Thread Starter
New Member
Understanding Arrays
I have an assignment that requires the use of arrays.
I need to know how to call an array from button to button.
The array is developed under the code of button A and needs to be used for calculations in the code of button B.
Also, they cannot be form-level.
-
Aug 8th, 2012, 01:07 AM
#2
Re: Understanding Arrays
On the subject of terminology, you don't call an array. The only things that get called are methods. Arrays and other objects would be accessed. Also, you're not passing anything from Button to Button. You have no code under your Buttons. The Buttons raise their Click event and that's it. You have methods that handle those Click events but those methods are members of the form. All your code is in the form and none of it in the Buttons.
As for the question, you're going to have to provide a more detailed explanation because what you're asking for sounds impossible. There's no issue using the same object in two separate methods but it is simply not possible to access a variable created in one method from another method. You can declare array variables in two different methods and assign the same array object to them no problem, but where does the array come from in the first place? If you create it in one of the methods and assign it only to the variable declared in that method then, as soon as the method completes, the variable loses scope and therefore ceases to exist. The array object it referred to continues to exist but there is no way to access it. The way you retain access to an object between method calls is to assign it to some other field or property, which is why your requirement not to do that seems to take the whole thing into the realms of fantasy.
Please provide a FULL and CLEAR explanation of the problem. While I never advocate people simply posting their assignment questions and expecting us to do their work for them, in this case I think that we need to see the actual assignment question to first determine whether it makes sense and then determine whether you have misinterpreted something.
-
Aug 8th, 2012, 08:07 AM
#3
Thread Starter
New Member
Re: Understanding Arrays
I apologize for my terrible use of terminology, however I am in an Programming Logic and Design Introductory Course.
So, in short, you are saying that in order for two button click event methods to use the same 3 arrays, the arrays must have form-level declaration?
I had to skip the class in which we discussed arrays in vb, so I had to play around to figure out how to use them, again I apologize for my Noob level.
-
Aug 8th, 2012, 08:24 AM
#4
Re: Understanding Arrays
If you want to access the same object from multiple methods then the object must be stored in a location that is accessible to all those methods. That means a variable, outside all of them.
-
Aug 8th, 2012, 08:51 AM
#5
Re: Understanding Arrays
To add to John's answer you'll want to look at the Scope of the arrays.
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Aug 8th, 2012, 10:48 AM
#6
Re: Understanding Arrays
I think you might be slightly confused as to what the assignment requires. Perhaps if you posted the assignment, we might be able to provide better help?
-
Aug 12th, 2012, 02:12 PM
#7
Thread Starter
New Member
Re: Understanding Arrays
I was slightly confused as to what my assignment was asking, the assignment mentioned I was to use form-level variables only when needed. I too quickly assumed that this referred to my arrays, which my instructor confirmed are to be form-level components.
Thanks for all the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|