Example

Get and Set Text Fields

Author: Carl Sassenrath
This example requires REBOL/View
Return to REBOL Cookbook

Here is an example of how to get a string that a user typed into a text field:


    out: layout [
        h2 "Text Field Example"
        f1: field
        button "Get It" [
            print f1/text
        ]
    ]
    view out

Type something into the field and click the button to see it on the console.

Here's how it works: when the layout is made, the field face is assigned to the f1 variable. After that, you can get or set the contents of the field by using f1/text.

Here is an example of how to set a text field:


    out: layout [
        h2 "Text Field Example"
        f1: field
        button "Set It" [
            f1/text: form now/date
            show f1
        ]
    ]
    view out

When you click the button, the field will get the current date as a string. Note the call to SHOW in order to display the change. This is required.

Here is another example:


    out: layout [
        h2 "Text Field Example"
        f1: field [
            f2/text: f1/text
            show f2
        ]
        f2: field
    ]
    view out

Now type something in the first field and press enter to see it appear in the second field.

Of course, this works for more than just text fields. This example changes a text line:


    out: layout [
        h2 "Text Field Example"
        f1: field [
            t1/text: f1/text
            show t1
        ]
        t1: text 300 bold navy
    ]
    view out

The text you type into the field will show up in the text string below it (after you hit enter).

Note that the text face is given a width of 300 (because no text was provided to it in the layout). If you forget to do that, you won't see the text correctly.


2006 REBOL Technologies REBOL.com REBOL.net