Solved

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

Posted on 2007-03-30
2
169 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 142

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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