WinBatch® Technical Support Forum

Archived Boards => WinBatch Dynamic Dialogs => Topic started by: stevengraff on March 11, 2014, 06:55:35 AM

Title: Competing events... control which takes precedence?
Post by: stevengraff on March 11, 2014, 06:55:35 AM
I have a dialog with a multiline edit box, and while the user types in to it, the callback routine calculates and posts the character count.

This same dialog has a sql query result in a mshtml com control that gets updated by a timer every 7 seconds.

Here's the problem, as you may have guessed: every seven seconds the user's typing gets interrupted because the timer kicks in and does its query.

Is there a way to "multi-thread" this, so the two events don't interfere with each other?

Or, maybe simpler, is there a way to not do the timer activities if it can be determined that the user is typing?
Title: Re: Competing events... control which takes precedence?
Post by: stevengraff on March 11, 2014, 07:01:19 AM
Solved it as follows, turning off the timer as soon as the typing begins (i.e. the Case EditText part is called), and turning it back on after each key stroke, to do nothing for 7 seconds; re-interruptable by the subsequent typing.

   Case EditText
   If ControlNum == 3
      DialogProcOptions(Schmandle, MSG_TIMER, 0)
document2.getElementByID("Alert").innerHTML = ""
msg = DialogControlGet(Schmandle, 3, 3)
totalLen = strLen(msg) + lenPref + lenSig
chars = strCat("Message length: ", totalLen) ; calculates the character count
DialogControlSet(Schmandle, 11, 4, chars)    ; updates the character count
if totalLen > (maxchars) then DialogControlSet(Schmandle, 3, 13, hotColor) ; alerts if text entered exceeds 140 characters
if totalLen >= (maxchars-20) & totalLen <= (maxchars-0) then DialogControlSet(Schmandle, 3, 13, warnColor)
if totalLen < (maxchars-20) then DialogControlSet(Schmandle, 3, 13, regColor) ; alerts if text entered exceeds 140 characters
      DialogProcOptions(Schmandle, MSG_TIMER, refresh)
      Return -2 ; Don't termnate the dialog
   endif
Title: Re: Competing events... control which takes precedence?
Post by: JTaylor on March 11, 2014, 08:57:45 AM
If you set the timer, it resets the time.   So if it was set for 7 seconds and 4 has passed and you set it for 7 seconds it will start the count over.  So, simply set the timer for 7 seconds with each keystroke and it will never kick in while they are typing.   If you don't want that long of a pause after typing set it for a shorter time and then check the value in the timer event and if less than 7 set it back to seven at that time.

I use this method for database queries when I want the typing to limit the list automatically but don't want it search with every keystroke.  I usually set it for .5 or 1 second so if they pause the search will kick in but while typing at a reasonable speed it resets the timer for the search.

Jim