Xbase Documentation

Tutorial: Using Forms with Scripts

[Note: This is an intermediate/advanced level tutorial. You are expected to know how to create forms and how to use the form design view.]

In this tutorial you will learn how to create mini applications with Xbase forms and scripts. We'll be building a Celsius to Fahrenheit temperature converter. So lets get started!

  1. Create a new document.
  2. Create a new form called "Converter" with no content table.
  3. Add a text field to your form by dragging one from the controls section in the options pane.
  4. Change the text field's label to "Celsius".
  5. Change the text field's script name, using the action inspector, to "celsius".
  6. Add another text field to your form.
  7. Change the second text field's label to "Fahrenheit".
  8. Change the second text field's script name to "fahrenheit".
  9. Select the Celsius text field and click "Add Action" in the toolbar.
  10. Now change the script so it looks like this:
    function form_celsius(ctrl) { Form.ControlNamed("fahrenheit").numValue = ctrl.numValue * 9/5 + 32; }


  11. Go back to the form, select the Fahenheit text field and click add action again. Then change new function to this:

    function form_fahrenheit(ctrl) { Form.ControlNamed("celsius").numValue = (ctrl.numValue - 32) * 5/9; }


  12. That's it! Switch to form data view. Type a number into a text fields and press return. The other text field should update with the converted value.