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 18 1665
"Nathan" <nk************ *********@softh ome.net> schrieb 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?
The array is filled in the constructor before InitializeCompo nent is called
and consequently before Label0...Label5 have been set, so you are filling
the array with 6 x Nothing.
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Nathan, I'd have it a guess that an instance of Label0, Label1, Label2,
Label3, Label4, and Label5 hasn't been created when you declare LabelArray
outside the subroutine FillLabels (and with class scope); LabelArray would
have length 5 but be full of 'Nothing'.
Within your for next loop, add a
if labelarray(a) is nothing then
msgbox "nothing"
end if
to see if this is the case. To elaborate further, if you have your
LabelArray declared at class level, derived from for example
System.Windows. Forms. Form, the "space" for the array will be allocated but
instances of the controls on the form Label0, .... won't have been. What you
are wanting is to populate LabelArray after Form_Load has executed - then
Label0, Label1... etc are instances of Label. As I see it when you are
running your application now, they probably aren't.
Regards
Hexathioorthoox alate
"Nathan" <nk************ *********@softh ome.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. 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
I mean length 6 :(
"Hexathioorthoo xalate" <ru***@spamerem ove.clara.co.uk > wrote in message
news:10******** ********@echo.u k.clara.net... Nathan, I'd have it a guess that an instance of Label0, Label1, Label2, Label3, Label4, and Label5 hasn't been created when you declare LabelArray outside the subroutine FillLabels (and with class scope); LabelArray would have length 5 but be full of 'Nothing'.
Within your for next loop, add a
if labelarray(a) is nothing then msgbox "nothing" end if
to see if this is the case. To elaborate further, if you have your LabelArray declared at class level, derived from for example System.Windows. Forms. Form, the "space" for the array will be allocated
but instances of the controls on the form Label0, .... won't have been. What
you are wanting is to populate LabelArray after Form_Load has executed - then Label0, Label1... etc are instances of Label. As I see it when you are running your application now, they probably aren't.
Regards Hexathioorthoox alate
"Nathan" <nk************ *********@softh ome.net> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. 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
Hi Nathan,
To add to the others how to resolve it Dim LabelArray() as Label = {Label0, Label1, Label2, Label3, Label4,
Label5} \\ Private Sub FillLabels dim a as integer For a = 0 to 5
LabelArray(a) = new Label
Msgbx(LabelArra y(a).Text) Next End Sub \\
I hope this helps,
Cor
"Cor" <no*@non.com> schrieb Dim LabelArray() as Label = {Label0, Label1, Label2, Label3, Label4, Label5} \\ Private Sub FillLabels dim a as integer For a = 0 to 5
LabelArray(a) = new Label
Msgbx(LabelArra y(a).Text) Next End Sub \\ I hope this helps,
I don't think so. I think he wants the 6 labels in the array, not 6
invisible labels. ;-)
--
Armin
Hi Armin I don't think so. I think he wants the 6 labels in the array, not 6 invisible labels. ;-) Dim LabelArray() as Label = {Label0, Label1, Label2, Label3, Label4, Label5} \\
Private Sub FillLabels dim a as integer For a = 0 to 5
LabelArray(a) = new Label
labelarray(i).W idth = 40
labelarray(i).H eight = 20
labelarray(i).L ocation = New System.Drawing. Point(10, Cint(i * 21))
labelarray(i).T ext = i.ToString
Me.Controls.Add (labelarray(i)) Msgbx(LabelArra y(a).Text) Next End Sub \\
Better?
Cor
"Cor" <no*@non.com> schrieb LabelArray(a) = new Label labelarray(i).W idth = 40 labelarray(i).H eight = 20 labelarray(i).L ocation = New System.Drawing. Point(10, Cint(i * 21)) labelarray(i).T ext = i.ToString Me.Controls.Add (labelarray(i))
Better?
Yes, but what I meant was that I'd created the array later because I think
the labels have been added by the designer.
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Me.LabelArray = New Label() _
{Label0, Label1, Label2, Label3, Label4, Label5}
End Sub
--
Armin
* "Nathan" <nk************ *********@softh ome.net> scripsit: 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)
'MsgBox'...
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?
The code should work. Where do you call the procedure? In the form's
constructor prior to calling 'InitializeComp onent'? At this time, the
controls are not yet instantiated, so you will get the exception.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Thanks for the help so far. To be more specific, I already have the labels
created in the form designer, and I want to add them to a new array. The
array declaration appears after the form designer generated code, and just
before any other written code. I had guessed that for some reason the
labels didn't "exist" yet when the dim statement appeared. I still don't
understand why, though.
I put a msgbox in the for...loop as Hex suggested, and the msgbox appeared
as expected. The sub where the for...loop appears is called by the frm_Load
event. To give you a visual:
\\
+ Windows Form Designer generated code
Dim LabelArray() as Label = {Label0, Label1, Label2, Label3, Label4, Label5}
Private Sub frm1_Load(etc.. ..) Handles MyBase.Load
FillLabels()
End Sub
Private Sub FillLabels()
'Code...
End Sub
\\
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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...
|
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,...
|
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:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
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
|
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...
| |