Solved

control name as text

Posted on 2004-10-10
3
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - String Manipulation Scenario 2 42
how to make search between pages 17 56
GUID's in SQL Server 4 27
Help solve error message when converting date using vb.NET 10 38
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

736 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