Solved

I have: Name of a button, and I want to change the text of it

Posted on 2007-03-30
2
175 Views
Last Modified: 2010-04-23
I want to change the text of a button. What I know is the name of the button and the new text.

So I have tried this:

Private Sub me_text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles me_text.TextChanged
        GetControl(me_control.Text).Text = me_text.Text
    End Sub

    Private Function GetControl(ByVal _Name As String) As Button
        Dim entry As Control
        For Each entry In Controls                                     'searching all controls
            If entry.GetType.Name = "Button" Then            'only search for name if its a button
                If entry.Name = _Name Then                         'if the button has the name of the button that I want
                    Return entry                                              'return entry, which is a button
                End If
            End If
        Next
    End Function

What is wrong?

Thanks

Sven
0
Comment
Question by:Ruttensoft
2 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18822399
what error do you get?

maybe this works better:
 Private Function GetControl(ByVal _Name As String) As Button
        Dim entry As Control
        For Each entry In Controls                                     'searching all controls
            If entry.GetType.Name = "Button" Then            'only search for name if its a button
                If entry.Name = _Name Then                         'if the button has the name of the button that I want
                    Return entry as Button                                              'return entry, which is a button
                End If
            End If
        Next
    End Function
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 18822506
Hi Ruttensoft,

If you are using VS2005, you can use this....

     CType(Me.Controls.Find(me_control.Text, True)(0), Button).Text = me_text.Text

Else, you might like to take a look at this -> http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21564702.html

Regards,

Wayne
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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