473,786 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Declaring control array

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:

\\
Private Sub FillLabels
dim a as integer
For a = 0 to 5
Msgbx(LabelArra y(a).Text)
Next
End Sub
\\

I get an "Object reference not set to an instance of an object" error. If I
put the Dim statement inside the subroutine, it works fine. Am I doing
something wrong in declaring the array to have class scope?

Once again, thanks for the help.

Nathan


Nov 20 '05
18 1666
"Nathan" <nk************ *********@softh ome.net> wrote...
I'm guessing that as a workaround I could delete the labels from the form
designer and insert them via code (as per Cor's post), but surely there's another way to make this work.


You don't have to go to all that trouble.

Your dim statement shouldn't include the assignment of the labels. Objects
aren't created line-by-line while stepping through the code. If you dim the
array in your form and add the labels to it in form_load I would be shocked
if it doesn't work.

Tom
Nov 20 '05 #11
Cor
Hi Nathan,

I did not know what you wanted,
If you want this, the labelarea has to be global
just beneath the Window form designer code
private labelarea(6) as labels

Somewhere else but I think the best place is the formload event you
labelarea(0) = label0
labelarea(1)=la bel1
etc,

Then your loop works everywhere.

I hope this helps?

Cor
Nov 20 '05 #12
Thanks Cor and Tom. I figured something like that would work; however, is
there a way to add multiple controls to array in one line, without doing it
line by line? To be more truthful with you, I have tons of controls that
need to be added to eleven different arrays. If I must do it line by line,
I can just stick those lines of code in their own sub in a minimized region
where they are out of the way. I was just wondering if there's a way to do
it all in one line, as it is when initializing the array.

"Cor" <no*@non.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Hi Nathan,

I did not know what you wanted,
If you want this, the labelarea has to be global
just beneath the Window form designer code
private labelarea(6) as labels

Somewhere else but I think the best place is the formload event you
labelarea(0) = label0
labelarea(1)=la bel1
etc,

Then your loop works everywhere.

I hope this helps?

Cor


Nov 20 '05 #13
On 2004-01-04, Nathan <nk************ *********@softh ome.net> wrote:
Thanks Cor and Tom. I figured something like that would work;
however, is there a way to add multiple controls to array in one line,
without doing it line by line? To be more truthful with you, I have
tons of controls that need to be added to eleven different arrays. If
I must do it line by line, I can just stick those lines of code in
their own sub in a minimized region where they are out of the way. I
was just wondering if there's a way to do it all in one line, as it is
when initializing the array.


Private LabelArray() As Label

Private Sub Form_Load(...)
LabelArray = new Label() { Label1, Label2, Label3, Label4}
End Sub

--
David
dfoster at
hotpop dot com
Nov 20 '05 #14
Once again, thank you!

"David" <df*****@127.0. 0.1> wrote in message
news:sl******** ************@wo ofix.local.dom. ..
On 2004-01-04, Nathan <nk************ *********@softh ome.net> wrote:
Thanks Cor and Tom. I figured something like that would work;
however, is there a way to add multiple controls to array in one line,
without doing it line by line? To be more truthful with you, I have
tons of controls that need to be added to eleven different arrays. If
I must do it line by line, I can just stick those lines of code in
their own sub in a minimized region where they are out of the way. I
was just wondering if there's a way to do it all in one line, as it is
when initializing the array.


Private LabelArray() As Label

Private Sub Form_Load(...)
LabelArray = new Label() { Label1, Label2, Label3, Label4}
End Sub

--
David
dfoster at
hotpop dot com

Nov 20 '05 #15
"David" <df*****@127.0. 0.1> schrieb
Private LabelArray() As Label

Private Sub Form_Load(...)
LabelArray = new Label() { Label1, Label2, Label3, Label4}
End Sub

The same I wrote the day before. ;-)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #16
Cor
Hi Armin,

The same I wrote the day before. ;-)


Stimt aber not complete, I was knocking on my head when I saw Davids answer,
that he made as addition on mine and remembered direct your answer.

The difference is that you did not tell that the array had to be declared
global.

(I never thought that it should go because of all the documentation and
samples in this newsgroup accoording control arrays)

However when I saw Tom's message I thought also why not.

And it is of course a nice solution I think.

Cor
Nov 20 '05 #17
"Cor" <no*@non.com> schrieb
The same I wrote the day before. ;-)


Stimt aber not complete, I was knocking on my head when I saw Davids
answer, that he made as addition on mine and remembered direct your
answer.

The difference is that you did not tell that the array had to be
declared global.


"global"? At class level?
Nathan wrote: "I've declared a "control array" just after the WFD generated
code like this:", so I assumed it is declared as at class level (as a
field).

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #18
Cor
Hi Armin,
WFD


You are right, maybe it is because I never declare something there with Dim

Again a long thread for nothing

(Not about)

(But I still find it a nice solution so I learned from it)

:-))

Cor
Nov 20 '05 #19

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

Similar topics

3
2185
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
12
3888
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm trying to access // that has two ports. Each port has 10 sequential // registers. Create a...
3
1289
by: captainphoenix | last post by:
vb 2005 what i have is an interface designed to act like an order form at a bookstore, like the one a clerk would use to ring up a customer for books. The btnList button connects all the textboxes in the gui to an msaccess database with all the information about pricing and what courses the textbooks correlate to. the best way for me to describe it is a row of textboxes for inputs for isbn#, textbook name, the course it correlates to, pricing,...
4
1655
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:
0
9492
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
10360
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
10163
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
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
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
6744
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
5397
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...
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.