声明控制数组 [英] Declaring control array

查看:56
本文介绍了声明控制数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你想知道我为什么发布这么多问题,那是因为我想要在bin吉他世界纪录中输入
。但是因为我发布了很多,所以我试着让它们变得简单。这是(我希望)一个简单的:


我已经声明了一个控制数组。就像WFD生成的代码之后:


Dim LabelArray()标签= {Label0,Label1,Label2,Label3,Label4,Label5}


但是当我尝试做这样的事情时:


\\

私人子补充标签

dim a为整数

对于a = 0到5

Msgbx(LabelArray(a).Text)

下一页

结束子

\\


我得到一个对象引用未设置为对象的实例错误。如果我将
将Dim语句放在子例程中,它就可以了。我在声明阵列有类范围的时候做了什么?$ / b
$ b再一次,谢谢你的帮助。


Nathan

解决方案

" Nathan" < NK ********************* @ softhome.net> schrieb

我已经声明了一个控制数组。就像WFD生成的代码之后
这样:

Dim LabelArray()as Label = {Label0,Label1,Label2,Label3,Label4,
Label5}
<但是,当我尝试这样做时:

\\
私人子填充标签
将整数调整为整数
对于a = 0到5
Msgbx(LabelArray(a).Text)
下一页
结束子
\\

我得到一个对象引用未设置为对象的实例
错误。如果我将Dim语句放在子例程中,它可以正常工作。我在声明数组有类范围时做错了吗?




在调用InitializeComponent之前,数组在构造函数中填充

因此在Label0 ... Label5之前已经设置好了,所以你要填充

阵列,只需6 x Nothing。

-

Armin

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


Nathan,我猜对了一个实例Label0,Label1,Label2,

当你在子程序FillLabels(和类范围)之外声明LabelArray

时,还没有创建Label3,Label4和Label5; LabelArray将

的长度为5,但充满了''Nothing''。


在你的下一个循环中,添加一个

如果labelarray(a)什么都不是那么

msgbox没什么

结束如果


看如果是这样的话。进一步详细说明,如果你在类级别声明了

LabelArray,那么派生自例如

System.Windows.Forms。形式,空间对于数组将被分配,但

表格Label0上的控件实例,....不会。你想要的是在Word_Load执行后填充LabelArray - 然后

Label0,Label1 ......等是Label的实例。我现在正在运行您的应用程序时看到它,它们可能不是。


问候

Hexathioorthooxalate


" Nathan" < NK ********************* @ softhome.net>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...

如果你我想知道为什么我发布了这么多问题,这是因为我想要在吉尼斯世界纪录中输入一个条目。但是因为我发布了
这么多,我试着让它们变得简单。这是(我希望)一个简单的:

我已经宣布了一个控制数组。在WFD生成的代码之后就像
这样:
Dim LabelArray()as Label = {Label0,Label1,Label2,Label3,Label4,
Label5}
但是当我尝试做这样的事情:

\\
Private Sub FillLabels
dim a为整数
对于a = 0到5
Msgbx(LabelArray( a)。文本)
下一页
结束子
\\
我得到一个对象引用没有设置为对象的实例。错误。如果
我将Dim语句放在子例程中,它可以正常工作。我在声明阵列有类范围时做错了什么?

再次感谢你的帮助。

Nathan


我的意思是长度6 :(

" Hexathioorthooxalate" ru *** @ spameremove.clara.co.uk>写道在消息中

新闻:10 **************** @ echo.uk.clara.net ...

Nathan,我猜想当你在子程序FillLabels之外声明LabelArray时,还没有创建Label0,Label1,Label2,
Label3,Label4和Label5的实例(以及类范围); LabelArray将长度为5但充满''Nothing''。

在你的下一个循环中,添加一个

如果labelarray(a )什么都没有呢
msgbox没什么
结束如果确定是这样的话。要进一步说明,如果你的
LabelArray在类级别,例如来自系统。 Windows.Forms。形式,空间。对于数组将分配
但是表格Label0上的控件实例,....不会。你想要的
是在Form_Load执行后填充LabelArray - 然后
Label0,Label1 ......等是Label的实例。正如我现在运行您的应用程序时所看到的那样,它们可能不是。

问候
Hexathioorthooxalate


" ;森" < NK ********************* @ softhome.net>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...

如果你想知道为什么我发布了这么多问题,这是因为我想在吉尼斯世界纪录中录入一个条目。但是因为我发布了很多

,我试着让它们变得简单。这是(我希望)一个简单的:

我已经宣布了一个控制数组。就在WFD生成代码之后


这个:


Dim LabelArray()as Label = {Label0,Label1,Label2,Label3,Label4,

Label5}


但是当我尝试做这样的事情时:

\\
Private Sub FillLabels
dim a为整数
对于a = 0到5
Msgbx(LabelArray(a).Text)
下一页
End Sub
\\

我得到一个对象引用未设置为对象的实例错误。



如果我

将Dim语句放在子例程中,它可以正常工作。我在声明阵列有类范围时做错了什么?

再次感谢你的帮助。

Nathan



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(LabelArray(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


解决方案

"Nathan" <nk*********************@softhome.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(LabelArray(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 InitializeComponent 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
Hexathioorthooxalate

"Nathan" <nk*********************@softhome.net> wrote in message
news:%2****************@TK2MSFTNGP12.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(LabelArray(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 :(
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in message
news:10****************@echo.uk.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
Hexathioorthooxalate

"Nathan" <nk*********************@softhome.net> wrote in message
news:%2****************@TK2MSFTNGP12.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(LabelArray(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




这篇关于声明控制数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆