IF-THEN-ELSE OR INPUT VALIDATION

Until now we have seen some objects that are what people from IT (Information Technology) call: "interface controls":

Buttons are to fire actions and the other 3 are for inputs from the user.

If all the users will have only a few options of input, RadioButtons is the right way to go. If there are many possibilities of input or the input is pre-undefined (by example, if the user needs to input his name or his salary) you will use a TextField.

At this last case is a good option to make a validation of the entry.

Squeak (Smalltalk) has resources to programming comparisons. Something like:

      | x y |
      x := 1.
      y := 2.
      (x > y)
         ifTrue: [
          "do something".
                        ]
         ifFalse: [
          "do something".
            ].

You can write many lines of code between the square brackets.

At the first line we have created two: temporary variables.

I hope you have noted how we do comments in Squeak scripts (double quotations).

For comparisons we use:

      >      "greater than"
      <      "less than"
      =      "equal to in value"
      ~=     "not equal in value"
      >=     "greater than or equal to"
      <=     "less than or equal to"

And the signals for AND and OR are:

     (a > 0) & (b < 0)     "Returns true if a is positive 
                             and b is negative,Otherwise false."

      (a > 0) | (b < 0)     "Returns true if either a is
                             positive or b is negative."

The exercice/demo of this lesson is very simple. The user will type a number that needs to be between some values and we need to do the validation.

Like ever, the script is glued to the output object (a Text).

Remember to do: "accept" for your script!.

Look the script in the figure:

And play with our project:




PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE