When changing data via a control bound to a data source, there is some delay
until the change actually registers. This is a particular problem with a
check box in a grid, where I am trying to count the number of .T. values in
that field. I usually have interactivechange trigger a timer which waits a
couple tens of a second, then performs the count routine. However, this is
not reliable.

For instance, if I change the value of myfield clicking a checkbox bound to
mytable.myfield, then issue

SELECT COUNT(*) FROM mytable WHERE myfield

the count is invariably off by one until after some period of time has
passed, which may be as long as a second or so.

All data is local, no network is involved. The table has about 5000 records.

Anyone have a good solution?

Re: timing of updating data from a control by Gregory

Gregory
Thu Jan 11 03:56:18 CST 2007

Paul,

A couple of suggestions - none tested

(1) Set the focus to anything else but the checkbox, then count

or

(2) in the interactivechange
=m.this.SetFocus()


(3) in the interactivechange
repl (this.ControlSource) with this.value in (juststem(this.ControlSource))
=this.Refresh()
do the count

or

(4) initialize the count on a form level (counter)
in the interactivechange, increment/decrement the form counter

Gregory
__________
"Paul Pedersen" <nospam@no.spam> wrote in message
news:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl...
> When changing data via a control bound to a data source, there is some
> delay until the change actually registers. This is a particular problem
> with a check box in a grid, where I am trying to count the number of .T.
> values in that field. I usually have interactivechange trigger a timer
> which waits a couple tens of a second, then performs the count routine.
> However, this is not reliable.
>
> For instance, if I change the value of myfield clicking a checkbox bound
> to mytable.myfield, then issue
>
> SELECT COUNT(*) FROM mytable WHERE myfield
>
> the count is invariably off by one until after some period of time has
> passed, which may be as long as a second or so.
>
> All data is local, no network is involved. The table has about 5000
> records.
>
> Anyone have a good solution?
>
>
>


Re: timing of updating data from a control by Roger

Roger
Thu Jan 11 08:21:48 CST 2007

"Paul Pedersen" <nospam@no.spam> wrote in message
news:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl
> When changing data via a control bound to a data source, there is
> some delay until the change actually registers. This is a particular
> problem with a check box in a grid, where I am trying to count the
> number of .T. values in that field. I usually have interactivechange
> trigger a timer which waits a couple tens of a second, then performs
> the count routine. However, this is not reliable.
>
> For instance, if I change the value of myfield clicking a checkbox
> bound to mytable.myfield, then issue
>
> SELECT COUNT(*) FROM mytable WHERE myfield
>
> the count is invariably off by one until after some period of time has
> passed, which may be as long as a second or so.
>
> All data is local, no network is involved. The table has about 5000
> records.
> Anyone have a good solution?

Paul,

Further to Gregory's post, I got this to work by doing the
following (and you don't need a timer):

Place a command button (Cmd1) somewhere on your form
and set its Style property to 1 (invisible).

In your Grid.Checkbox.Click event put the following code:

ThisForm.LockScreen = .T.

ThisForm.Cmd1.SetFocus
This.SetFocus

Select Count(*) from mytable;
Where myfield = .T. ;
Into array laCount

ThisForm.LockScreen = .F.

The Click event seems to work more reliably
than InteractiveChange (for a checkbox in a grid).

Essentially, you need to move the focus off
the checkbox (as Gregory mentioned) and ideally
away from the grid before doing the Select Count(*)
etc.

HTH

-Roger



Re: timing of updating data from a control by Paul

Paul
Thu Jan 11 22:39:04 CST 2007

Thanks for the suggestions. Believe it or not, I had already tried all of
them except changing the focus. Unfortunately, that didn't work either.
Neither did moving it all into the click method.

Surprisingly enough, the method that works most often is still the timer.
But it's far from reliable.

The problem with using an external counter is that it's difficult to tell
whether the user is checking or unchecking the box.




"Paul Pedersen" <nospam@no.spam> wrote in message
news:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl...
> When changing data via a control bound to a data source, there is some
> delay until the change actually registers. This is a particular problem
> with a check box in a grid, where I am trying to count the number of .T.
> values in that field. I usually have interactivechange trigger a timer
> which waits a couple tens of a second, then performs the count routine.
> However, this is not reliable.
>
> For instance, if I change the value of myfield clicking a checkbox bound
> to mytable.myfield, then issue
>
> SELECT COUNT(*) FROM mytable WHERE myfield
>
> the count is invariably off by one until after some period of time has
> passed, which may be as long as a second or so.
>
> All data is local, no network is involved. The table has about 5000
> records.
>
> Anyone have a good solution?
>
>
>



Re: timing of updating data from a control by Paul

Paul
Thu Jan 11 23:18:33 CST 2007

OK, I figured out why my previously-usually-reliable timer method wasn't
working in this case. I had a buffered table, and forgot to put WITH
BUFFERING in my count query. Duh. And oops!

But your setfocus method works even better than the timer. So, thanks! I
just put THIS.SETFOCUS in interactivechange, then call the count routine and
it works like a charm. Now I can get rid of that timer junk.

Thanks again.



"Paul Pedersen" <nospam@no.spam> wrote in message
news:eXo1UOgNHHA.4928@TK2MSFTNGP06.phx.gbl...
> Thanks for the suggestions. Believe it or not, I had already tried all of
> them except changing the focus. Unfortunately, that didn't work either.
> Neither did moving it all into the click method.
>
> Surprisingly enough, the method that works most often is still the timer.
> But it's far from reliable.
>
> The problem with using an external counter is that it's difficult to tell
> whether the user is checking or unchecking the box.
>
>
>
>
> "Paul Pedersen" <nospam@no.spam> wrote in message
> news:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl...
>> When changing data via a control bound to a data source, there is some
>> delay until the change actually registers. This is a particular problem
>> with a check box in a grid, where I am trying to count the number of .T.
>> values in that field. I usually have interactivechange trigger a timer
>> which waits a couple tens of a second, then performs the count routine.
>> However, this is not reliable.
>>
>> For instance, if I change the value of myfield clicking a checkbox bound
>> to mytable.myfield, then issue
>>
>> SELECT COUNT(*) FROM mytable WHERE myfield
>>
>> the count is invariably off by one until after some period of time has
>> passed, which may be as long as a second or so.
>>
>> All data is local, no network is involved. The table has about 5000
>> records.
>>
>> Anyone have a good solution?
>>
>>
>>
>
>



Re: timing of updating data from a control by Curious

Curious
Thu Jan 11 23:26:32 CST 2007

In your checkbox.InteractiveChange event add "=TableUpdate(.t.)" to the
end of any code you have in there. VFP likes to buffer records and
entire tables when they are small enough. This will for the data to be
written to the table so any subsequent queries on the table will
reflect the changes.

CJ

On Jan 11, 9:39 pm, "Paul Pedersen" <nos...@no.spam> wrote:
> Thanks for the suggestions. Believe it or not, I had already tried all of
> them except changing the focus. Unfortunately, that didn't work either.
> Neither did moving it all into the click method.
>
> Surprisingly enough, the method that works most often is still the timer.
> But it's far from reliable.
>
> The problem with using an external counter is that it's difficult to tell
> whether the user is checking or unchecking the box.
>
> "Paul Pedersen" <nos...@no.spam> wrote in messagenews:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl...
>
> > When changing data via a control bound to a data source, there is some
> > delay until the change actually registers. This is a particular problem
> > with a check box in a grid, where I am trying to count the number of .T.
> > values in that field. I usually have interactivechange trigger a timer
> > which waits a couple tens of a second, then performs the count routine.
> > However, this is not reliable.
>
> > For instance, if I change the value of myfield clicking a checkbox bound
> > to mytable.myfield, then issue
>
> > SELECT COUNT(*) FROM mytable WHERE myfield
>
> > the count is invariably off by one until after some period of time has
> > passed, which may be as long as a second or so.
>
> > All data is local, no network is involved. The table has about 5000
> > records.
>
> > Anyone have a good solution?


Re: timing of updating data from a control by Gregory

Gregory
Fri Jan 12 03:34:11 CST 2007

Paul,

The controlSource gets updated when the focus moves off the control

Why not use suggestion #4 ?

Gregory
_
"Paul Pedersen" <nospam@no.spam> wrote in message
news:uXuqYkgNHHA.1252@TK2MSFTNGP02.phx.gbl...
> OK, I figured out why my previously-usually-reliable timer method wasn't
> working in this case. I had a buffered table, and forgot to put WITH
> BUFFERING in my count query. Duh. And oops!
>
> But your setfocus method works even better than the timer. So, thanks! I
> just put THIS.SETFOCUS in interactivechange, then call the count routine
> and it works like a charm. Now I can get rid of that timer junk.
>
> Thanks again.
>
>
>
> "Paul Pedersen" <nospam@no.spam> wrote in message
> news:eXo1UOgNHHA.4928@TK2MSFTNGP06.phx.gbl...
>> Thanks for the suggestions. Believe it or not, I had already tried all of
>> them except changing the focus. Unfortunately, that didn't work either.
>> Neither did moving it all into the click method.
>>
>> Surprisingly enough, the method that works most often is still the timer.
>> But it's far from reliable.
>>
>> The problem with using an external counter is that it's difficult to tell
>> whether the user is checking or unchecking the box.
>>
>>
>>
>>
>> "Paul Pedersen" <nospam@no.spam> wrote in message
>> news:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl...
>>> When changing data via a control bound to a data source, there is some
>>> delay until the change actually registers. This is a particular problem
>>> with a check box in a grid, where I am trying to count the number of .T.
>>> values in that field. I usually have interactivechange trigger a timer
>>> which waits a couple tens of a second, then performs the count routine.
>>> However, this is not reliable.
>>>
>>> For instance, if I change the value of myfield clicking a checkbox bound
>>> to mytable.myfield, then issue
>>>
>>> SELECT COUNT(*) FROM mytable WHERE myfield
>>>
>>> the count is invariably off by one until after some period of time has
>>> passed, which may be as long as a second or so.
>>>
>>> All data is local, no network is involved. The table has about 5000
>>> records.
>>>
>>> Anyone have a good solution?
>>>
>>>
>>>
>>
>>
>
>


Re: timing of updating data from a control by Paul

Paul
Fri Jan 12 12:10:02 CST 2007

Because if I remember right, in either interactivechange or in click, I
don't know whether the new value of the checkbox will be .T. or .F.

In any case, #2 is simpler, especially since the counting routine can be
called from other places as well.



"Gregory Adam" <GregoryAdam@PleaseReplyViaNewsGroup.com> wrote in message
news:edeVVEjNHHA.3944@TK2MSFTNGP06.phx.gbl...
> Paul,
>
> The controlSource gets updated when the focus moves off the control
>
> Why not use suggestion #4 ?
>
> Gregory
> _
> "Paul Pedersen" <nospam@no.spam> wrote in message
> news:uXuqYkgNHHA.1252@TK2MSFTNGP02.phx.gbl...
>> OK, I figured out why my previously-usually-reliable timer method wasn't
>> working in this case. I had a buffered table, and forgot to put WITH
>> BUFFERING in my count query. Duh. And oops!
>>
>> But your setfocus method works even better than the timer. So, thanks! I
>> just put THIS.SETFOCUS in interactivechange, then call the count routine
>> and it works like a charm. Now I can get rid of that timer junk.
>>
>> Thanks again.
>>
>>
>>
>> "Paul Pedersen" <nospam@no.spam> wrote in message
>> news:eXo1UOgNHHA.4928@TK2MSFTNGP06.phx.gbl...
>>> Thanks for the suggestions. Believe it or not, I had already tried all
>>> of them except changing the focus. Unfortunately, that didn't work
>>> either. Neither did moving it all into the click method.
>>>
>>> Surprisingly enough, the method that works most often is still the
>>> timer. But it's far from reliable.
>>>
>>> The problem with using an external counter is that it's difficult to
>>> tell whether the user is checking or unchecking the box.
>>>
>>>
>>>
>>>
>>> "Paul Pedersen" <nospam@no.spam> wrote in message
>>> news:O4OnGiRNHHA.536@TK2MSFTNGP02.phx.gbl...
>>>> When changing data via a control bound to a data source, there is some
>>>> delay until the change actually registers. This is a particular problem
>>>> with a check box in a grid, where I am trying to count the number of
>>>> .T. values in that field. I usually have interactivechange trigger a
>>>> timer which waits a couple tens of a second, then performs the count
>>>> routine. However, this is not reliable.
>>>>
>>>> For instance, if I change the value of myfield clicking a checkbox
>>>> bound to mytable.myfield, then issue
>>>>
>>>> SELECT COUNT(*) FROM mytable WHERE myfield
>>>>
>>>> the count is invariably off by one until after some period of time has
>>>> passed, which may be as long as a second or so.
>>>>
>>>> All data is local, no network is involved. The table has about 5000
>>>> records.
>>>>
>>>> Anyone have a good solution?
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>



Re: timing of updating data from a control by Gregory

Gregory
Fri Jan 12 20:42:59 CST 2007


"Paul Pedersen" <nospam@no.spam> wrote in message
news:eTTmeTnNHHA.4912@TK2MSFTNGP02.phx.gbl...
> Because if I remember right, in either interactivechange or in click, I
> don't know whether the new value of the checkbox will be .T. or .F.

Supposing that there are no nulls involved

&& checkbox interactive change
=dodefault()
with m.thisform
.Counter = .Counter + iif(m.this.value, 1, -1)
endwith

> In any case, #2 is simpler, especially since the counting routine can be
> called from other places as well.
>

Yes, but it may be time consuming


Re: timing of updating data from a control by Paul

Paul
Sun Jan 14 13:04:36 CST 2007


"Gregory Adam" <GregoryAdam@PleaseReplyViaNewsGroup.com> wrote in message
news:e2RdPyrNHHA.4172@TK2MSFTNGP03.phx.gbl...
>
> "Paul Pedersen" <nospam@no.spam> wrote in message
> news:eTTmeTnNHHA.4912@TK2MSFTNGP02.phx.gbl...
>> Because if I remember right, in either interactivechange or in click, I
>> don't know whether the new value of the checkbox will be .T. or .F.
>
> Supposing that there are no nulls involved
>
> && checkbox interactive change
> =dodefault()
> with m.thisform
> .Counter = .Counter + iif(m.this.value, 1, -1)
> endwith

Yes, but during code run in the interactivechange event, or the click event
for that matter, is the checkbox .T. or .F.? I don't think that can be
determined with certainty until the code has completed running.





Re: timing of updating data from a control by Jack

Jack
Sun Jan 14 16:46:02 CST 2007

On Sun, 14 Jan 2007 11:04:36 -0800, "Paul Pedersen" <nospam@no.spam>
wrote:

>
>"Gregory Adam" <GregoryAdam@PleaseReplyViaNewsGroup.com> wrote in message
>news:e2RdPyrNHHA.4172@TK2MSFTNGP03.phx.gbl...
>>
>> "Paul Pedersen" <nospam@no.spam> wrote in message
>> news:eTTmeTnNHHA.4912@TK2MSFTNGP02.phx.gbl...
>>> Because if I remember right, in either interactivechange or in click, I
>>> don't know whether the new value of the checkbox will be .T. or .F.
>>
>> Supposing that there are no nulls involved
>>
>> && checkbox interactive change
>> =dodefault()
>> with m.thisform
>> .Counter = .Counter + iif(m.this.value, 1, -1)
>> endwith
>
>Yes, but during code run in the interactivechange event, or the click event
>for that matter, is the checkbox .T. or .F.? I don't think that can be
>determined with certainty until the code has completed running.

I have lots of code that checks This.Value in InteractiveChange() and
it always has the correct (new) value.