DoEvents inside TrueDBGrid RowColChange Event 
Author Message
 DoEvents inside TrueDBGrid RowColChange Event

I have some code inside a TrueDBGrid 7.0 dbGrid controls RowColChange event.
This code segment includes a DoEvents command to allow other Windows operations
to function.

When the code enters this segment and excutes the DoEvents command, the
RowColChange event fires a second time, runs thru the entire subroutines code
(without firing the RowColChange event a third time), then completes the rest of
the code.   What is causing this to happen?

The following code causes the subsequent debug window printout

public sub grdEvent_RowColChange(.....)

Debug.print "A"
Debug.print "B"
DoEvents
Debug.print "C"

end sub

Immediate window:
A
B
A
B
C
A



Tue, 06 Jul 2004 05:01:38 GMT  
 DoEvents inside TrueDBGrid RowColChange Event
I have zero experience with that grid... but if you want to stop this
recursion, you can use a Static variable..

This needs a textbox (Text1)..
'==============
Private Sub Text1_Change()
   Static bHereAlready As Boolean
   If Not bHereAlready Then
      bHereAlready = True
      '===your code
      '
      Debug.Print "A"
      Debug.Print "B"
      'fire change to see it work
      Text1.Text = "12345"
      Debug.Print "C"
      '===end of your code
      bHereAlready = False
   End If
End Sub
'==============
'This is what shows...
A
B
C

you can also use a static to limit the number of recursions..
'==============
Private Sub Text1_Change()
   Static iRecursCount As Integer
   If iRecursCount <= 1 Then 'runs only twice
      iRecursCount = iRecursCount + 1
      '===your code
      '
      Debug.Print "A"
      Debug.Print "B"
      'fire change to see it work
      Text1.Text = "12345"
      'fire change to see it work
      Text1.Text = "54321"
      Debug.Print "C"
      '===end of your code
      iRecursCount = iRecursCount - 1
   End If
End Sub
'==============
'This is what shows...
A
B
A
B
C
C

I hope trying to stop/control it was the question<g>

--
Ken Halter (VB-MVP)
Please respond only to the newsgroups so all can benefit.


Quote:
> I have some code inside a TrueDBGrid 7.0 dbGrid controls RowColChange
event.
> This code segment includes a DoEvents command to allow other Windows
operations
> to function.

> When the code enters this segment and excutes the DoEvents command, the
> RowColChange event fires a second time, runs thru the entire subroutines
code
> (without firing the RowColChange event a third time), then completes the
rest of
> the code.   What is causing this to happen?

> The following code causes the subsequent debug window printout

> public sub grdEvent_RowColChange(.....)

> Debug.print "A"
> Debug.print "B"
> DoEvents
> Debug.print "C"

> end sub

> Immediate window:
> A
> B
> A
> B
> C
> A



Tue, 06 Jul 2004 10:50:44 GMT  
 DoEvents inside TrueDBGrid RowColChange Event
Yes, Ken, stopping the action was what I wanted, and altho I use static
variable on a regular basis, I didn't even consider it in this instance.
Thanks

I found some notes on the Component1 web site which implied that if the grid
is visible when you populate it, this occurs, so I am going to try setting
its visible property to false at the beginning of the routine and true at
the end of the routine to see if that works.  If not, I'll go with the
static variable.


Quote:
> I have zero experience with that grid... but if you want to stop this
> recursion, you can use a Static variable..

> This needs a textbox (Text1)..
> '==============
> Private Sub Text1_Change()
>    Static bHereAlready As Boolean
>    If Not bHereAlready Then
>       bHereAlready = True
>       '===your code
>       '
>       Debug.Print "A"
>       Debug.Print "B"
>       'fire change to see it work
>       Text1.Text = "12345"
>       Debug.Print "C"
>       '===end of your code
>       bHereAlready = False
>    End If
> End Sub
> '==============
> 'This is what shows...
> A
> B
> C

> you can also use a static to limit the number of recursions..
> '==============
> Private Sub Text1_Change()
>    Static iRecursCount As Integer
>    If iRecursCount <= 1 Then 'runs only twice
>       iRecursCount = iRecursCount + 1
>       '===your code
>       '
>       Debug.Print "A"
>       Debug.Print "B"
>       'fire change to see it work
>       Text1.Text = "12345"
>       'fire change to see it work
>       Text1.Text = "54321"
>       Debug.Print "C"
>       '===end of your code
>       iRecursCount = iRecursCount - 1
>    End If
> End Sub
> '==============
> 'This is what shows...
> A
> B
> A
> B
> C
> C

> I hope trying to stop/control it was the question<g>

> --
> Ken Halter (VB-MVP)
> Please respond only to the newsgroups so all can benefit.



> > I have some code inside a TrueDBGrid 7.0 dbGrid controls RowColChange
> event.
> > This code segment includes a DoEvents command to allow other Windows
> operations
> > to function.

> > When the code enters this segment and excutes the DoEvents command, the
> > RowColChange event fires a second time, runs thru the entire subroutines
> code
> > (without firing the RowColChange event a third time), then completes the
> rest of
> > the code.   What is causing this to happen?

> > The following code causes the subsequent debug window printout

> > public sub grdEvent_RowColChange(.....)

> > Debug.print "A"
> > Debug.print "B"
> > DoEvents
> > Debug.print "C"

> > end sub

> > Immediate window:
> > A
> > B
> > A
> > B
> > C
> > A



Tue, 06 Jul 2004 19:20:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DoEvents inside COM event?

2. VB Grid RowColChange Event Vs TextBox LostFocus Event

3. Disabling Fixed Rows on Grid's RowColChange Event

4. Bug?... with Datagrid RowColChange Event

5. Data Grid RowColChange Event

6. GetKeyState Fails In RowColChange Event

7. Firing events from a form inside a class inside a test app

8. DoEvents() inside a class?

9. 'DoEvents' inside ActiveX DLL

10. DoEvents and Form_Timer event

11. DoEvents not doing any events

12. Multiple Timers, Events Queue, DoEvents Don't Work

 

 
Powered by phpBB® Forum Software