如何使用变量来引用控件? [英] how to use variable to refer to a control?

查看:97
本文介绍了如何使用变量来引用控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中有几个文本框控件。

我将它们命名为txt1,txt2,... txt10。

如何在循环中引用它们获取每个

控件的文本属性值?


x = 1到10

值= txt(x).text


next x


谢谢


Bill

I have several textbox controls in a form,.
I name them txt1, txt2, ... txt10.
How dow I refer to them in a loop to get the value in text proerty of each
control?

For x = 1 to 10

value = txt(x).text

next x

Thanks

Bill

推荐答案

因为我试图给出我的控件商业意义名称,所以我不会根据整数索引迭代
。我已经成功地组装了

容器内的类似规则控件,例如面板或tabcontrol

标签页和使用容器控件集合。


将textitem作为文本框进行暗淡

对于form1.controls中的每个textitem

''做东西

next textitem


对于panel1.controls中的每个文本项目

''做东西

下一个textitem


对于每个文本项目在tabcontrol1.tabpages(1).controls

''做的东西

下一个textitem


如果我必须应用差异基于确切名称的规则,如果

或textitem.name上的选择案例将起作用。


HTH,

Keith


Bill Nguyen写道:
Since I try to give my controls business-meaning names, I don''t iterate
based on an integer index. I have had some success organizing
similar-ruled controls within containers such as panels or tabcontrol
tabpages and using the container controls collection.

Dim textitem as textbox
For each textitem in form1.controls
''do stuff
next textitem

For each textitem in panel1.controls
''do stuff
next textitem

For each textitem in tabcontrol1.tabpages(1).controls
''do stuff
next textitem

If I have to apply a differential rule based on the exact name, an if
or select case on textitem.name will work.

HTH,
Keith

Bill Nguyen wrote:

我在表单中有几个文本框控件。

我将它们命名为txt1,txt2,... txt10。

如何在循环中引用它们以获取每个文本的值。

控制?


x = 1到10

value = txt(x).text


next x


谢谢


比尔
I have several textbox controls in a form,.
I name them txt1, txt2, ... txt10.
How dow I refer to them in a loop to get the value in text proerty of each
control?

For x = 1 to 10

value = txt(x).text

next x

Thanks

Bill


Keith;


这很棒。

但是,我仍然需要能够参考实际的控制名称。

有办法吗?


再次感谢


Billl

" kgerritsen" < ki *** @ drexel.eduwrote in message

news:11 ********************* @ k70g2000cwa.googlegro ups。 com ...
Keith;

This is great.
However, I still need to be able to refer to an actual control name.
Is there a way to do that?

Thanks again

Billl
"kgerritsen" <ki***@drexel.eduwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...

因为我试图给出我的控件商业意义名称,所以我不会基于整数迭代

指数。我已经成功地组装了

容器内的类似规则控件,例如面板或tabcontrol

标签页和使用容器控件集合。


将textitem作为文本框进行暗淡

对于form1.controls中的每个textitem

''做东西

next textitem


对于panel1.controls中的每个文本项目

''做东西

下一个textitem


对于每个文本项目在tabcontrol1.tabpages(1).controls

''做的东西

下一个textitem


如果我必须应用差异基于确切名称的规则,如果

或textitem.name上的选择案例将起作用。


HTH,

Keith


Bill Nguyen写道:
Since I try to give my controls business-meaning names, I don''t iterate
based on an integer index. I have had some success organizing
similar-ruled controls within containers such as panels or tabcontrol
tabpages and using the container controls collection.

Dim textitem as textbox
For each textitem in form1.controls
''do stuff
next textitem

For each textitem in panel1.controls
''do stuff
next textitem

For each textitem in tabcontrol1.tabpages(1).controls
''do stuff
next textitem

If I have to apply a differential rule based on the exact name, an if
or select case on textitem.name will work.

HTH,
Keith

Bill Nguyen wrote:

>我在表单中有几个文本框控件。
我的名字他们txt1,txt2,... txt10。
如何在循环中引用它们以获得每个
控件的文本属性值?
对于x = 1到10
值= txt(x).text

接下来x

谢谢

比尔
>I have several textbox controls in a form,.
I name them txt1, txt2, ... txt10.
How dow I refer to them in a loop to get the value in text proerty of
each
control?

For x = 1 to 10

value = txt(x).text

next x

Thanks

Bill



比尔,


你有没有谷歌这个新闻组,你的问题几乎每天两次

,并且几乎有三个答案。这次我是这样做的。

http://groups.google.com/group/micro...n&lr=&ie=UTF-8


我相信它昨天在那里


Cor

" Bill Nguyen" < bi ***************** @ jaco.comschreef在bericht

新闻:uj ************* *@TK2MSFTNGP03.phx.gbl ...
Bill,

Did you ever Google this newsgroup, your question comes almost twice a day
and has forever almost three answers. This time I do it like this.

http://groups.google.com/group/micro...n&lr=&ie=UTF-8

I am sure it was there yesterday

Cor
"Bill Nguyen" <bi*****************@jaco.comschreef in bericht
news:uj**************@TK2MSFTNGP03.phx.gbl...

>我在表单中有几个文本框控件。

我将它们命名为txt1 ,txt2,... txt10。

如何在循环中引用它们以获取每个

控件的文本属性值?


x = 1到10

value = txt(x).text


next x


谢谢


比尔
>I have several textbox controls in a form,.
I name them txt1, txt2, ... txt10.
How dow I refer to them in a loop to get the value in text proerty of each
control?

For x = 1 to 10

value = txt(x).text

next x

Thanks

Bill



这篇关于如何使用变量来引用控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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