官术网_书友最值得收藏!

Restricting the user input

There is an old saying: garbage in and garbage out. This refers to users entering invalid data into a computerized system. Fortunately, we have some control over what users can input. This recipe shows you how this is done.

How to do it...

To restrict user input, perform the following steps:

  1. Create a new main stack.
  2. Drag a text input box to the stack's card.
  3. Add the following code to the text input box:
    on keyDown theKey
      if theKey is in "abcdefghijklmnopqrstuvwxyz" then
        pass keyDown
      else
         beep
        end if
      end keyDown

How it works...

By evaluating the user's input prior to allowing it to pass to the next level in the message chain, we can selectively accept or reject it.

There's more...

In this recipe, we intercepted messages from the keyboard using our on keyDown handler. In LiveCode, messages are triggered by events such as the mouseDown message being sent when the user selects/clicks on an object. In this example, the event was the clicking of the object and mouseDown was the message. Messages have an informational path in that they are first heard or are available at the object, group (if applicable), card, stack, and finally, at the LiveCode Engine level.

主站蜘蛛池模板: 沅江市| 和田市| 南丹县| 沁水县| 图木舒克市| 芮城县| 油尖旺区| 白河县| 莱西市| 靖宇县| 永福县| 长乐市| 青海省| 西城区| 黔东| 峡江县| 宜君县| 桐柏县| 石柱| 大邑县| 河池市| 开阳县| 古交市| 南川市| 宜兴市| 资溪县| 台湾省| 永清县| 江都市| 固镇县| 万宁市| 合肥市| 新昌县| 仙居县| 吴忠市| 和静县| 万源市| 大邑县| 涡阳县| 航空| 民丰县|