EnigmaticallySpeaking
System Reliability Specialist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial I will teach you how to get the name of a specific TextBoxes by using For Each Loop in VB.Net. This method will determine what are the names of your TextBoxes that you drag it on the Form. You will be able to find out the specific name of the TextBox because it will be seen in each TextBoxes.
So let’s begin:
Open Visual Studio and create a new Project. Drag all the TextBoxes and a Button. Then, do the Form just like this.
Double click the Button to fire the click
event handler in the Method.
Now, create a variable that represents the control.
After that, Loop the control that you have created.
Then, check if the type of the control is a Textbox and if it’s true, then perform the process that puts the name of the TextBox to itself. Do this code inside the Loop.
And here are the codes that we made.
Press F5 to run your project and click the Button to fire the code in the method.
So let’s begin:
Open Visual Studio and create a new Project. Drag all the TextBoxes and a Button. Then, do the Form just like this.

Double click the Button to fire the click
event handler in the Method.
Now, create a variable that represents the control.
- Dim
txt As
Control
After that, Loop the control that you have created.
- For
Each
txt In
Me
.
Controls
- Next
Then, check if the type of the control is a Textbox and if it’s true, then perform the process that puts the name of the TextBox to itself. Do this code inside the Loop.
- If
txt.
GetType
Is
GetType
(
TextBox)
Then
- txt.
Text
=
txt.
Name
- End
If
And here are the codes that we made.
- Private
Sub
Button1_Click(
ByVal
sender As
System.
Object
, ByVal
e As
System.
EventArgs
)
Handles
Button1.
Click
- Dim
txt As
Control
- For
Each
txt In
Me
.
Controls
- If
txt.
GetType
Is
GetType
(
TextBox)
Then
- txt.
Text
=
txt.
Name
- End
If
- Next
- End
Sub
Press F5 to run your project and click the Button to fire the code in the method.