Solved

CallByName Button Caption

Posted on 2004-09-09
7
506 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …

636 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