Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CallByName Button Caption

Posted on 2004-09-09
7
Medium Priority
?
512 Views
Last Modified: 2012-08-13
Can someone tell me how to use callbyname to set the caption on a button.  I want to pass in a string indicating the button name.

I found this, but I don't want to pass in the control, I want to pass in "Command1"

CallByName Command1, "Caption", VbLet, "OK"
0
Comment
Question by:Fraser_Admin
[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
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 12019542
Instead of VbLet, use CallType.Set:

CallByName(TextBox1, "Text", CallType.Set, "New Text")

from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctCallByNameFunction.asp?frame=true
0
 

Author Comment

by:Fraser_Admin
ID: 12020212
You are still calling this with the control textbox1.  I want to call it with the control name "Textbox1"
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12020216
yes
CallByName(YourButtonObject ,"Caption", CallType.Set, "New Text")
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 22

Expert Comment

by:cookre
ID: 12020707
Uh, that was an example - use your own control names, attribute names, and values.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 12021261
Fraser_Admin is looking to use the name of the control, not a reference to the control.

The control name "Command1" and "Caption" property suggests VB6:

    Private Sub Command1_Click()
        CallByName Me.Controls("Command1"), "Caption", VbLet, "OK"
    End Sub

Regards,

Idle_Mind
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12021344
In VB.Net, you need a helper function to get the control reference from the control name like this:

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim c As Control = getControlByName("Button4")
        If Not (c Is Nothing) Then
            CallByName(c, "Text", CallType.Set, "OK")
        Else
            MsgBox(sender.name, MsgBoxStyle.Critical, "Control Not Found")
        End If
    End Sub

    Private Function getControlByName(ByVal controlName As String) As Control
        Dim i As Integer
        Dim ctl As Control

        controlName = controlName.ToLower
        For Each ctl In Me.Controls
            If ctl.Name.ToLower.Equals(controlName) Then
                Return ctl
            End If
        Next ctl
    End Function
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12023201
you may also write a self callbyname sub like

private Function  myCallByName(byval ObjName as string,ByVal ProcName As String, ByVal UseCallType As CallType,  ByVal ParamArrayArgs() As Object )As Object

 Dim i As Integer
        Dim ctl As Control

        controlName = controlName.ToLower
        For Each ctl In Me.Controls
            If ctl.Name.ToLower.Equals(ObjName.toLower) Then
                exit for
            End If
        Next ctl
        If ctl.Name.ToLower.Equals(controlName.toLower) Then
           return CallByName(ctl,ProcName,UseCallType,ParamArrayArgs)
        else
           return nothing
        end if
end sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Make the most of your online learning experience.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

722 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