INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

"Do not click me more than Once", CommandButton said. by NasibKalsi
Posted: 28 May 07 (Edited 7 Dec 13)

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 

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close