Solved

CallByName Button Caption

Posted on 2004-09-09
7
492 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countPairs challenge 7 65
How does Google get such fast response times? 5 151
PHP question(s) about order of output 9 57
Beginner to Unreal Engine 4 5 57
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now