Best way to prevent command button invoking recursion 
Author Message
 Best way to prevent command button invoking recursion

I'm not sure if this is the right terminology, but what is the best way to
prevent command button invoking recursion?

In other words, if the command button has the focus and the user clicks on
it very fast, I want to ensure that the code being executed does not get
interrupted by another click event.

This is how I approach it right now. I'm using the TAG property to ensure
that the code in the click event will not be interrupted at all-- is there a
more elegant way?:

Public Sub cmdMeasureTemperature_Click()
    With Me
        If .cmdMeasureTemperature.Tag = "BUSY" Then Exit Sub
        .cmdMeasureTemperature.Tag = "BUSY"
    End With

    ' **** Put code that I do want to be interrupted by another
cmdMeasureTemperature_Click event here
    '
    '
    ' ****

    cmdMeasureTemperature.Tag = "NOT BUSY"

End Sub

The strings that I use in my code are actually public string constants, but
I hard-coded "BUSY" and "NOT BUSY" above for clarity.

I appreciate anyone's help with a more elegant or simple solution.

Thanks,

Ken Pergola



Wed, 21 May 2003 03:00:00 GMT  
 Best way to prevent command button invoking recursion
maybe u can disable the button and enabling it again

Quote:
> I'm not sure if this is the right terminology, but what is the best way to
> prevent command button invoking recursion?

> In other words, if the command button has the focus and the user clicks on
> it very fast, I want to ensure that the code being executed does not get
> interrupted by another click event.

> This is how I approach it right now. I'm using the TAG property to ensure
> that the code in the click event will not be interrupted at all-- is there
a
> more elegant way?:

> Public Sub cmdMeasureTemperature_Click()
>     With Me
>         If .cmdMeasureTemperature.Tag = "BUSY" Then Exit Sub
>         .cmdMeasureTemperature.Tag = "BUSY"
>     End With

>     ' **** Put code that I do want to be interrupted by another
> cmdMeasureTemperature_Click event here
>     '
>     '
>     ' ****

>     cmdMeasureTemperature.Tag = "NOT BUSY"

> End Sub

> The strings that I use in my code are actually public string constants,
but
> I hard-coded "BUSY" and "NOT BUSY" above for clarity.

> I appreciate anyone's help with a more elegant or simple solution.

> Thanks,

> Ken Pergola



Thu, 22 May 2003 03:00:00 GMT  
 Best way to prevent command button invoking recursion
Thanks for the suggestion, but disabling/enabling the control is not an
option. Granted the way I'm currently doing works great, but seems a bit
kludgey.

Hopefully others may have some suggestions.

Thanks,

Ken Pergola


Quote:
> maybe u can disable the button and enabling it again


> > I'm not sure if this is the right terminology, but what is the best way
to
> > prevent command button invoking recursion?

> > In other words, if the command button has the focus and the user clicks
on
> > it very fast, I want to ensure that the code being executed does not get
> > interrupted by another click event.

> > This is how I approach it right now. I'm using the TAG property to
ensure
> > that the code in the click event will not be interrupted at all-- is
there
> a
> > more elegant way?:

> > Public Sub cmdMeasureTemperature_Click()
> >     With Me
> >         If .cmdMeasureTemperature.Tag = "BUSY" Then Exit Sub
> >         .cmdMeasureTemperature.Tag = "BUSY"
> >     End With

> >     ' **** Put code that I do want to be interrupted by another
> > cmdMeasureTemperature_Click event here
> >     '
> >     '
> >     ' ****

> >     cmdMeasureTemperature.Tag = "NOT BUSY"

> > End Sub

> > The strings that I use in my code are actually public string constants,
> but
> > I hard-coded "BUSY" and "NOT BUSY" above for clarity.

> > I appreciate anyone's help with a more elegant or simple solution.

> > Thanks,

> > Ken Pergola



Thu, 22 May 2003 03:00:00 GMT  
 Best way to prevent command button invoking recursion
I usually use something like:

Sub Command1_Click
   Static Working as Integer

   If Working Then Exit Sub
   Working = True
   'do your stuff here
   Working = False
Exit Sub

Also, if you're doing calculations or sorting or stuff, if
there is no DoEvents or other code allowing the system to
process clicks, you can sometimes prevent the multiple clicks.
Of course, they'll probably be stored and occur when control is
available.

--

~~~~~~~~~~~~~~~~~~~~
"For every action, there is an equal and opposite criticism."


Quote:
> Thanks for the suggestion, but disabling/enabling the control
is not an
> option. Granted the way I'm currently doing works great, but
seems a bit
> kludgey.

> Hopefully others may have some suggestions.

> Thanks,

> Ken Pergola



> > maybe u can disable the button and enabling it again


> > > I'm not sure if this is the right terminology, but what
is the best way
> to
> > > prevent command button invoking recursion?

> > > In other words, if the command button has the focus and
the user clicks
> on
> > > it very fast, I want to ensure that the code being

executed does not get

- Show quoted text -

Quote:
> > > interrupted by another click event.

> > > This is how I approach it right now. I'm using the TAG
property to
> ensure
> > > that the code in the click event will not be interrupted
at all-- is
> there
> > a
> > > more elegant way?:

> > > Public Sub cmdMeasureTemperature_Click()
> > >     With Me
> > >         If .cmdMeasureTemperature.Tag = "BUSY" Then Exit
Sub
> > >         .cmdMeasureTemperature.Tag = "BUSY"
> > >     End With

> > >     ' **** Put code that I do want to be interrupted by
another
> > > cmdMeasureTemperature_Click event here
> > >     '
> > >     '
> > >     ' ****

> > >     cmdMeasureTemperature.Tag = "NOT BUSY"

> > > End Sub

> > > The strings that I use in my code are actually public
string constants,
> > but
> > > I hard-coded "BUSY" and "NOT BUSY" above for clarity.

> > > I appreciate anyone's help with a more elegant or simple
solution.

> > > Thanks,

> > > Ken Pergola



Fri, 23 May 2003 09:08:49 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Preventing command-line-invoked VB app to exit?

2. Invoking a command button from a menu bar

3. invoking a command button with a Function Key

4. Prevent Double Click from running command button twice?

5. dropdownlists and grids, which ways is the best?

6. good ways to use recordsets without autocommit?

7. Better ways to schedule?

8. good ways to use recordsets without autocommit?

9. Better ways to put text into textbox??

10. Any ways to make focus on Label control like focus in button control

11. Help on best way to invoke other programs

12. Best way to invoke CR from VB

 

 
Powered by phpBB® Forum Software