Solved

control name as text

Posted on 2004-10-10
3
193 Views
Last Modified: 2010-04-23
i know this is farily easy, but i dont know what to search for

im wanting to control a bunch of different controls, and i dont want to use a control array...what i want to do is pass the text which will be the name

so something along the lines of

"text1".Text

thanks

~b
0
Comment
Question by:bramsquad
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 12273004
You can use something like this:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objTB As TextBox

        objTB = FindControl("TextBox1")
        If Not (objTB Is Nothing) Then
            objTB.Text = "Surpise!"
        Else
            MessageBox.Show("Control not found!")
        End If
    End Sub

    Function FindControl(ByVal pName As String) As Control
        For Each x As Control In Me.Controls
            If x.Name.ToUpper = pName.ToUpper Then
                Return x
            End If
        Next
    End Function
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12273013
Maybe this way,

Dim oControl As Control
   For Each oControl In Me.Controls
     If oControl.Name = "TextBox1" Then
        Exit For
     End If
Next

' oControl is the control that you searching
MsgBox(oControl.Text)
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12273028
Sorry, That was concurrency :D
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now