Page 1 of 1

Auto-calculate from Text Fields

Posted: Sat Jul 17, 2010 8:11 pm
by dragontologist
Hi all; I've been working in Revolution for a while now and have been unable to find a command for a simple auto-calculate action. Currently, I have a "calculate" button that has to be manually pressed after entering in an integer (it displays the number divided by 3). I would like it to AUTOMATICALLY update the second field when someone enters an integer in the first field (also acceptable for it to calculate when the selection changes or they tab to the next field). I have tried a few things and been unable to come up with the solution:

on revSelectedObjectChanged
on revSelectionChanged

Any help would be appreciated!

Re: Auto-calculate from Text Fields

Posted: Sat Jul 17, 2010 9:42 pm
by bangkok
Here you go.

The idea is to work with keyDown plus a regular expression to accept only digits, and another handler to handle the special case of backspace key

Code: Select all

on KeyDown theKey
   if matchText(theKey,"[0-9]") then 
      put thekey after me
      put me/3 into fld "theResult"
   else
      beep
   end if
end KeyDown

Re: Auto-calculate from Text Fields

Posted: Wed Jul 21, 2010 8:49 pm
by dunbarx
A more general solution, so that one can enter data in the middle of a number string and also not get waylaid if you enter a "Q", for example, is this in the field script:

Code: Select all

on rawkeyUp var
   if numToChar(var) is in ".0123456789" or var = 65288 then
      put me/3 into fld "gg"
   end if
end rawkeyUp
   
on keyDown var
    if  var is in ".0123456789" then pass keyDown
end keyDown
Craig Newman