Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Location
    Pittsburgh, Pennsylvania
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A Control as an Argument (Visual Basic 6)

    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.

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Control as an Argument (Visual Basic 6)

    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)
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Star Lounger
    Join Date
    Sep 2001
    Location
    Pittsburgh, Pennsylvania
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A Control as an Argument (Visual Basic 6)

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •