473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Nov 16 '08 #1
4 1779

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" <pa******@thetravelintexans.comschreef in bericht
news:gf**********@news.motzarella.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

Nov 16 '08 #2
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|Protected|Friend|Private] _
[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.
Nov 17 '08 #3


"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:et**************@TK2MSFTNGP02.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
Nov 17 '08 #4
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]
http://www.vbdotnetcoder.com

"Mythran" <My*****@community.nospamschreef in bericht
news:CC**********************************@microsof t.com...
>

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:et**************@TK2MSFTNGP02.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


Nov 17 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Friday | last post by:
Sorry if this is the wrong group. I tried to find the one I thought would be most relevant. I'm an old PHP guy, who knows little about asp and NOTHING about asp.net, but need to learn at least...
5
by: ms_chika | last post by:
Hi to all, I have this problem in declaring a two-dimesional array, how will i declare such array with unknown number of rows? Your help will be very much appreciated. Thanks in advance. ...
18
by: Nathan | last post by:
If you're wondering why I post so many questions, it's because I want to make an entry in the Guinness Book of World Records. But because I post so many, I try to make them simple. Here is (I...
3
by: mark | last post by:
When I declare an array as double(,) then try to use it I get an error: "Object reference not set to an instance of an object." I have found that I can redim the array and all is well. Is my...
1
by: John Dann | last post by:
Is there a way of declaring an array of a structure where the structure has a constructor? So if I had a structure say Friend MyStructure prop1 as integer prop2 as string sub New (p1 as...
3
by: hn.ft.pris | last post by:
I've got following code test C++'s functor. For the sake of easy-reading, I omit some declearations. #include <algorithm> #include <functional> using namespace std;
16
by: dejavu33 | last post by:
Hi! I dont understand arrays very much. Im trying to create an array of up to 100 positive numbers with the use of -1 to stop entering if the user needs an array containing less than 100...
5
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, I am declaring an element like this: public static List<myListElementmyList = new List<myListElement>(); I would like to declare an array of this myList. How would I modify the...
4
by: Peter Duniho | last post by:
On Thu, 14 Aug 2008 18:56:00 -0700, Phill <Phill@discussions.microsoft.comwrote: For future reference, if you are asking for help with an error (compile or execution), you really should post...
8
by: bintom | last post by:
What are the differences between the following methods of declaring strings? char string1 = "C++ forum"; char* string2 = "C++ forum"; I know that the first uses the array notation, whereas...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.