Prevent Unwanted Recursion

A bug affecting the Sheridan 3D Controls appears in VB 4.0a. I don’t believe it was in 4.0, and I am certain it was not in 3.0. In any case, even if you use 4.0, you should pay attention because the newer OCX may be installed already on users’ machines when your apps are distributed. I use the Sheridan command buttons quite a bit for their ability to display an icon as well as text, and I ran into this problem when I installed VB 4.0a.If the user double-clicks on a common dialog box (for example, to select a file), and the double click is physically located above a Sheridan 3D command button, the Click procedure of that command button will be fired. To test this, start a new project and place a Sheridan command button and a common dialog control on Form1. In the Click procedure of the command button, include this code:

 Private Sub SSCommand1_Click()	Const CDERR_CANCEL = &H7FF3	CommonDialog1.DialogTitle = "Open File"	CommonDialog1.filename = "*.*"	CommonDialog1.DefaultExt = ".*"	CommonDialog1.CancelError = True	CommonDialog1.Filter = "All Files (*.*)|*.*"	On Error Resume Next	CommonDialog1.Action = 1	If Err = CDERR_CANCEL Then		Exit Sub	End If	On Error GoTo 0End Sub

Run the program, click on the command button, and when the common dialog appears, move it so that the name of any file appears over the button. Double-click on the file name. The common dialog will disappear and a new one will appear, resulting from the SSCommand1_Click event firing again.The solution is to declare a static “flag” variable, FalseClick, within the button’s Click event. Then change the code in the SSCommand1_Click procedure to read

 Private Sub SSCommand1_Click()	Const CDERR_CANCEL = &H7FF3	Static FalseClick As Boolean	If FalseClick Then Exit Sub	FalseClick = True	CommonDialog1.DialogTitle = "Open File"	CommonDialog1.filename = "*.*"	CommonDialog1.DefaultExt = ".*"	CommonDialog1.CancelError = True	CommonDialog1.Filter = "All Files (*.*)|*.*"	On Error Resume Next	CommonDialog1.Action = 1	If Err = CDERR_CANCEL Then		FalseClick = False		Exit Sub	End If	On Error GoTo 0	DoEvents 'allow for recursion	FalseClick = FalseEnd Sub

The DoEvents function is required in any procedure that is so short that the last statement executes before the recursion begins. I hope this workaround can help others fix the same problem.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job