Link to home
Start Free TrialLog in
Avatar of nouellette
nouelletteFlag for United States of America

asked on

Simple VB Argument question...

I have a quick question about writing a routine..

I have a few controls on my form...let's say a few command buttons called command1 command2 and command3.  let's say I also have a checkbox1 and optionbutton1.

I then have a label box at the bottom.  I simply want my program to display the last control that was clicked or checked.  I'm having trouble finding how to take the control as an argument and display the actual control name in the label field.  Any help is appreciated.

Avatar of Jacamar
Jacamar

Here's  a quick example with 2 command buttons.  It's not very pretty, but it'll do what you want.

Private Sub Command1_Click()
Label1.Caption = Command1.Name
End Sub
Private Sub Command2_Click()
Label1.Caption = Command2.Name
End Sub
ASKER CERTIFIED SOLUTION
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nouellette

ASKER

jacamar...i can definitely do that...but thats getting around what i really need this to do...and thats to actually pass the control's name through to the label box.  basically to write a routine that takes a control as an argument and displays it in the label box.

i believe this is what deightons code is doing but im not 100% sure.
Deighton...works great...how can I also get the control TYPE for the "ActiveControl"?  cntX.Name pulls it's name just fine...but what could I use to also pull the actual type...meaning I could says "you selected " & cntX.Name & "Which is of type " &    

After Which is of type...I want to be able to pass the control type too...command button, option button, whatever the control object is...I would like to be able to pull that as well.
Deighton...works great...how can I also get the control TYPE for the "ActiveControl"?  cntX.Name pulls it's name just fine...but what could I use to also pull the actual type...meaning I could says "you selected " & cntX.Name & "Which is of type " &    

After Which is of type...I want to be able to pass the control type too...command button, option button, whatever the control object is...I would like to be able to pull that as well.
Nevermind...got it...just changed DISPLAY to NotifyControlType and pulled the control type as well as the control name.  Thanks!