Solved

CallByName Button Caption

Posted on 2004-09-09
7
486 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

705 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

21 Experts available now in Live!

Get 1:1 Help Now