473,505 Members | 15,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use variable to refer to a control?

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
Nov 13 '06 #1
10 8316
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:
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
Nov 13 '06 #2
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...
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:
>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

Nov 14 '06 #3
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...
>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

Nov 14 '06 #4
Cor;
What am I going to do with your link?

Bill
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uf**************@TK2MSFTNGP02.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...
>>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


Nov 14 '06 #5
http://groups.google.com/group/micro...rch+this+group

Herfried and I have endless answered on this,

(This is not all, only your exact question)

Cor

"Bill nguyen" <bi*****************@jaco.comschreef in bericht
news:Oq**************@TK2MSFTNGP04.phx.gbl...
Cor;
What am I going to do with your link?

Bill
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uf**************@TK2MSFTNGP02.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...
>>>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



Nov 14 '06 #6
Thanks.
I've only used Outlook Express to access this group.

Bill

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eM**************@TK2MSFTNGP04.phx.gbl...
http://groups.google.com/group/micro...rch+this+group

Herfried and I have endless answered on this,

(This is not all, only your exact question)

Cor

"Bill nguyen" <bi*****************@jaco.comschreef in bericht
news:Oq**************@TK2MSFTNGP04.phx.gbl...
>Cor;
What am I going to do with your link?

Bill
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uf**************@TK2MSFTNGP02.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...
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



Nov 15 '06 #7
Bill Nguyen wrote:
I have several textbox controls in a form,.
Good.
I name them txt1, txt2, ... txt10.
Not so good.
How dow I refer to them in a loop to get the value in text proerty of each
control?
(I love this answer; it /so/ annoys the .Net purists)

You use a Control Array. :-)

No, seriously.

You create an array of Controls, in this case TextBoxes, and loop
through that.

Dim textboxes As TextBox() = { txt1, txt2, ... txt10 }

For Each tb As TextBox in textboxes
value = tb.Text
Next

Regards,
Phill W.
Nov 15 '06 #8
I'm a .Net purist, and I think your answer is brilliant.
It's simple and concise, and gets the job done.

Does that mean I'm really *not* a .Net purist? :-(

Robin S.

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ej**********@south.jnrs.ja.net...
Bill Nguyen wrote:
>I have several textbox controls in a form,.

Good.
>I name them txt1, txt2, ... txt10.

Not so good.
>How dow I refer to them in a loop to get the value in text proerty of
each control?

(I love this answer; it /so/ annoys the .Net purists)

You use a Control Array. :-)

No, seriously.

You create an array of Controls, in this case TextBoxes, and loop through
that.

Dim textboxes As TextBox() = { txt1, txt2, ... txt10 }

For Each tb As TextBox in textboxes
value = tb.Text
Next

Regards,
Phill W.

Nov 16 '06 #9
RobinS wrote:
I'm a .Net purist, and I think your answer is brilliant.
It's simple and concise, and gets the job done.

Does that mean I'm really *not* a .Net purist? :-(
? Microsoft.Interaction.Responses.IndefiniteResponse s.Maybe

It used to be the case that mentioning "Control Array" (a very specific
VB "Proper" concept) in a .Net group brought down all manner of scorn of
the head of the unwary poster.

I suspect the previously vehement VB bashers are all off trying to work
out what their programs are doing now that they've dived into these
Generics things ... ;-)

Regards,
Phill W.
Nov 16 '06 #10
Well, there's no doubt that Generics are very cool.
But that doesn't mean there's no place in the world
for an array or arraylist. After all, even though
there are plasma tv's out there, some people still
rely on their Sony Wegas to do the job.

Robin S.

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ej**********@south.jnrs.ja.net...
RobinS wrote:
>I'm a .Net purist, and I think your answer is brilliant.
It's simple and concise, and gets the job done.

Does that mean I'm really *not* a .Net purist? :-(

? Microsoft.Interaction.Responses.IndefiniteResponse s.Maybe

It used to be the case that mentioning "Control Array" (a very specific VB
"Proper" concept) in a .Net group brought down all manner of scorn of the
head of the unwary poster.

I suspect the previously vehement VB bashers are all off trying to work
out what their programs are doing now that they've dived into these
Generics things ... ;-)

Regards,
Phill W.

Nov 16 '06 #11

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

Similar topics

1
1423
by: jon | last post by:
I would like to use the variable that the javascript creates as it parses the URL and be able to use this variable in other links on the same page. notice how link to page 2 has the token but the...
7
4269
by: Richard Hollenbeck | last post by:
Help! I don't know why this isn't working: Private Sub Combo9_Change() Dim UsersCourseSelection As String UsersCourseSelection = Me("Combo9").Value Combo13.Visible = True 'the following...
3
4130
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
2
2142
by: GY2 | last post by:
How do I refer to controls by a string variable name instead of by integer item index? A form contains 7 rich textbox controls labeled rtb1-rtb7. In VB6 I could use the following code to loop...
9
3070
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
53
26330
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global...
1
1349
by: Kev | last post by:
Hello All, I am attempting to use the variable "AccAllow " which is populated by opening a recordset. I am using AccAllowed to refer to a control on the active form (the Switchboard) but I am...
1
2136
by: bowl3969 | last post by:
I have a form with a lot of controls on it that will be used to update tables. The nature of the data is such that I will be running queries based on the control name. sqlstr="insert into tblgames...
5
17555
by: ChipR | last post by:
Question: Can I set a form's variable from another form? Details of my problem: In my Form1, I have Option Compare Database Option Explicit 'whether each tab has been updated, so they...
0
7218
marktang
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,...
0
7103
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...
0
7370
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...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
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...
0
5614
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,...
0
4701
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...
0
3188
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...
0
1532
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 ...

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.