quality control fields

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

quality control fields

Post by bsouthuk » Thu Jul 30, 2009 2:27 pm

Hi, i'm working on an application that requires the user to enter digits to answer questions the application asks them.

Basically, the user will click on a button field and a message will appear asking how much something cost. I want it so that if they was to enter a letter by accident then it would not allow it and request the information again.

At the moment my script is

Code: Select all

 ask"How much do you spend on clothes"
then put it into field "clothes"
What code could I add to the script that would not allow anything but digits?

Hope someone can help!

Cheers

Daniel

!Jerry!
Posts: 16
Joined: Tue Apr 07, 2009 3:49 pm

Post by !Jerry! » Thu Jul 30, 2009 5:06 pm

Hi bsouthuk,

you can try this:

Code: Select all

on mouseUp
   ask "How much do you spent on clothes?"
   if it is not a number then
      answer ">" &it&"<  - this is not a number, please enter a new value" 
   else
      -- save the value in variable "it" for next processing
      put it into fld "someField"
   end if   
end mouseUp
regards,
Jerry

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Jul 30, 2009 10:21 pm

There are various approaches, ranging from the "ask" situation Jerry volunteers, to "keyDown" or "rawKeyDown" handlers in the field to check input. Some examples are, I believe, in the "old" and the "new" RevOnline repositories. (In post Rev 3.5, look for the "Allowed Chars" stack by George C Brackett).
This is quite an old link but no doubt still valid and although it's quite weighty for a "simple" operation like this, is probably the most comprehensive example you'll find: http://www.sonsothunder.com/devres/revo ... fld007.htm

Perhaps a more succinct example is on the site of the late (and sadly missed) Eric Chatonet, http://www.sosmartsoftware.com/?r=revol ... ciels&l=en at #020 How to master users data in entry boxes

Post Reply