473,799 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1799

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******@thetr avelintexans.co mschreef in bericht
news:gf******** **@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

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|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.
Nov 17 '08 #3


"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:et******** ******@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
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*****@commun ity.nospamschre ef in bericht
news:CC******** *************** ***********@mic rosoft.com...
>

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


Nov 17 '08 #5

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

Similar topics

29
4058
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 enough to convert a favorite PHP script to work on an ASP.NET site. I'm experimenting with simple example scripts that will help me learn how to implement each "piece" of the puzzle.
5
10422
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. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
18
1667
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 hope) a simple one: I've declared a "control array" just after the WFD generated code like this: Dim LabelArray() as Label = {Label0, Label1, Label2, Label3, Label4, Label5} But when I try to do something like this:
3
2187
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 approach proper here or is the a better way for setting the instance of this specific format for an array. -- mark
1
1682
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 integer, p2 as string) me.prop1=p1 me.prop2=p2 End Sub
3
303
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
2168
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 elements. Ive seen them declared many ways but since im want to create an array of up to 100, Im using the following: Dim array as integer() Array=new integer (0 to 100) {} Console.Write("Please enter the value (-1 to stop)")
5
1921
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 declaration of myList so it will represents an array? Thanks Eitan
4
1657
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 the complete text of the error and be specific about when and where it happens. That said, in your code it's clear what's wrong:
8
3461
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 the second uses pointer notation. But apart from that what are the implications / dangers, etc. if any.
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10482
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.