• A Control as an Argument (Visual Basic 6)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » A Control as an Argument (Visual Basic 6)

    Author
    Topic
    #384234

    Is it possible to use a control as an argument for a sub or function? I need to write a routine that takes a control as an argument and displays in a label the name and type of the control. Does anyone know if this is possible? Thanks.

    Viewing 0 reply threads
    Author
    Replies
    • #658378

      Yep you sure can.

      Sub DisplayControlName(ctl As Control)
      Label1.Caption = ctl.Name
      End Sub

      If you want to call it from the click event of a button, you could use something like:

      Private Sub Command1_Click()
      DisplayControlName Me.Command1
      End Sub

      What this would do is, when you clicked on the Command Butoon, Command1 Label1’s caption would change to the name of the Command Button(Command1 in this case)

      • #658743

        Thank you very much, Bryan. That’s exactly what I needed.

    Viewing 0 reply threads
    Reply To: A Control as an Argument (Visual Basic 6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: