Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Do not click me more than Once", CommandButton said.

Tips -N- Tricks

"Do not click me more than Once", CommandButton said.

by  NasibKalsi  Posted    (Edited  )
Many a time, when user clicked the command button, waiting for results, and no application message appear, out of panic, user presses the CommandButton again, making the action to be repeated multiple times. There are many ways to stop this behavior, such as disabling the command button, changing colors, showing messages, etc. All this are just visual indicators, do not necessarily stop the user(by mistake, else) to not to click the command button. Following method will help to overcome this problem with some success.

Code:
* Modified on 2013-12-07
* One does not need to use the old code as was posted 2007-05-28.
* Add the following line to the beginning of the .click() event, i.e. disable the command button.

this.enabled = .f. 

* and also add the following line in the .valid() of the command button, i.e. enable the command button again 

this.enabled = .t.

* ---------------------------------------------------------------------------------------

* OneClick.prg
* Date : 2007-05-28
* 
* How to Test
* Click Multiple times on OneClick CommandButton within a short period of time.
* You will notice that OneClick will execute its code only once.
*
* Click Multiple times on MultiClick CommandButton within a short period of time.
* MultiClick will executes its code as many times as clicked.
*
* Implementation:
* Copy the code from OneClick.Valid() procedure to the valid() of your 
* CommandButton. Do not need to modify any other parameters or code of your
* application.
*
Public obj_test
obj_test = Newobject("OneClick")

obj_test.Show()


Return

Define Class OneClick As Form
	DoCreate = .T.
	Name = "OneClick"
	Caption = "Do not click me more than Once"

	Add Object cmdOneClick As CommandButton With ;
		Caption = 'OneClick', ;
		Height 	= 60, ;
		Top		= 10, ;
		Left	= 10

	Add Object cmdMultiClick As CommandButton With ;
		Caption = 'MultiClick', ;
		Height 	= 60, ;
		Top		= 90, ;
		Left	= 10


	Add Object txtShowResult As EditBox With ;
		Height 	= 160, ;
		Top		= 10, ;
		Left	= 160

	Procedure Init

	Return

	Procedure cmdOneClick.Click
	Local t_i

	With Thisform.txtShowResult
		.Value = .Value + "One   - " + Time() + Chr(13)
	Endwith
	* Add some strain
	For t_i = 1 To 1000000*40
	Endfor
	Endproc

	Procedure cmdOneClick.Valid
	Local t_j
	*
	* Each iteration adds .06 seconds delay. so choose the t_Max
	* according to your requirements
	#Define t_Max 50

	* Now Remove all Clicks
	For t_j = 1 To t_Max
		= Inkey('HME')
	endfor
	
	endproc
	

	Procedure cmdMultiClick.Click
	Local t_i

	With Thisform.txtShowResult
		.Value = .Value + "Multi - " + Time() + Chr(13)
	Endwith
	* Add some strain
	For t_i = 1 To 1000000*40
	Endfor
	Endproc
Enddefine
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top