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

G

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
 
G

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top