473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How 2 refer to controls by a string variable name instead of index

GY2
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 through each one but with .NET I'm having
trouble doing something just as efficient.

Is there not a way to refer to the control by its name or do I have to go
find its index number in order to point to it?

All help appreciated.
For K = 1 To 7
strWhichRTB = "rtb" & K
With Me(strWhichRTB)
.Text = "whatever"
End With
Next K

Feb 20 '06 #1
2 2136
Hi,

check this link:

http://dotnet.mvps.org/dotnet/faqs/?...eindex&lang=en

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"GY2" <2m*******@wherever.com> schreef in bericht
news:u9**************@TK2MSFTNGP10.phx.gbl...
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 through each one but with .NET I'm having
trouble doing something just as efficient.

Is there not a way to refer to the control by its name or do I have to go
find its index number in order to point to it?

All help appreciated.
For K = 1 To 7
strWhichRTB = "rtb" & K
With Me(strWhichRTB)
.Text = "whatever"
End With
Next K

Feb 20 '06 #2
GY2
Thanks a lot. This shows several ways to do it and I will probably go with
an array. Even so none of these methods are as clean as the old VB 6 way in
my opinion.

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:e$*************@TK2MSFTNGP12.phx.gbl...
Hi,

check this link:

http://dotnet.mvps.org/dotnet/faqs/?...eindex&lang=en

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"GY2" <2m*******@wherever.com> schreef in bericht
news:u9**************@TK2MSFTNGP10.phx.gbl...
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 through each one but with .NET I'm having
trouble doing something just as efficient.

Is there not a way to refer to the control by its name or do I have to go
find its index number in order to point to it?

All help appreciated.
For K = 1 To 7
strWhichRTB = "rtb" & K
With Me(strWhichRTB)
.Text = "whatever"
End With
Next K


Feb 20 '06 #3

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

Similar topics

1
by: Epson Barnett | last post by:
Hi, I'm new to C# and I'd like to be able to reference a field of an object using a variable instead of literal text. In the PHP scripting language, you can create a variable: $var = "name";...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
8
by: jcrouse | last post by:
I have a test app with one button and a context menu. When I click on the button, it adds a label with some properties, one being the assignment of the context menu. If I add 5 buttons then want to...
14
by: 97T | last post by:
Well this is still bugging me. I know there are other ways around this, but for a number of reasons I would like to be able to do this one simple thing. I have a form with a number of controls...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
10
by: Bill Nguyen | last post by:
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 =...
0
by: ansh20 | last post by:
I am adding run time generate controls in array. Now I want to retrieve those controls in other subroutine in same form. But when I am tring to retrieve control it says "Object variable or with...
11
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...
0
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...
0
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
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,...

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.