Solved

CallByName Button Caption

Posted on 2004-09-09
7
500 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
Independent Software Vendors: 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!

 
LVL 22

Expert Comment

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

Accepted Solution

by:
Mike Tomlinson earned 500 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 85

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Change the background and font colors in Notepad++ 5 155
Help Required 3 117
Run AutoHotkey script directly from Notepad++ 5 140
print bytes of an integer 6 25
This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

749 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