By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,482 Members | 3,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,482 IT Pros & Developers. It's quick & easy.

What can I check to see if a button has been clicked?

100+
P: 167
I have a scenario that I have several buttons on a form, let's say, button1 & button2. When button1 is clicked, it runs button1 code. When button2 is clicked, it runs button2 code and then calls button1_click and runs button1 code as well. My dilema is when the button1 code is run, I need to know if button1 was clicked causing the code to run as I need to add some code to only run if button1 was clicked and not if it is the case where button1 code is run because it was called by button2 when it was clicked. Hope this isn't too confusing!!
Jun 11 '07 #1
Share this Question
Share on Google+
4 Replies


FishVal
Expert 2.5K+
P: 2,653
I have a scenario that I have several buttons on a form, let's say, button1 & button2. When button1 is clicked, it runs button1 code. When button2 is clicked, it runs button2 code and then calls button1_click and runs button1 code as well. My dilema is when the button1 code is run, I need to know if button1 was clicked causing the code to run as I need to add some code to only run if button1 was clicked and not if it is the case where button1 code is run because it was called by button2 when it was clicked. Hope this isn't too confusing!!
I can only guess what you particulary want to run.
But in general I can recommend you the following solution.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btn1_Click()
  3.     'btn1 click specific code
  4.     CommonCode
  5.     'btn1 click specific code
  6. End Sub
  7.  
  8. Private Sub btn2_Click()
  9.     '....................
  10.     CommonCode
  11. End Sub
  12.  
  13. Private Sub CommonCode()
  14.     '......................
  15. End Sub
  16.  
  17.  
Good luck.
Jun 11 '07 #2

NeoPa
Expert Mod 15k+
P: 31,494
I would have said what Fish said. It's the way you should be thinking of doing this.
Jun 12 '07 #3

100+
P: 167
I was hoping I could use something like 'IF button1_click true'. I inherited this application which is not exactly structured and I am basically having to make things work. To pull the code out and create separate peices to run is not so easy the way it was written.
Jun 13 '07 #4

NeoPa
Expert Mod 15k+
P: 31,494
It's more OO (Object Oriented) than structured.
An event is fired that causes code to run (the event procedure). This is actually quite straightforward to code if you think it the right way.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.   'Do any Command1 only code here ...
  3.   Call Common()
  4.   '... or here
  5. End Sub
  6.  
  7. Private Sub Command2_Click()
  8.   'Do any Command2 only code here ...
  9.   Call Common()
  10.   '... or here
  11. End Sub
  12.  
  13. Private Sub Common()
  14.   'Code to do the common stuff
  15. End Sub
Jun 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.