Search code examples
rebolred-lang

Rebol code gui working but not clearing fields


I am trying following code where user enters 2 numbers and on clicking calculate button, answer should be shown. There are also buttons for clearing fields and for exiting.

REBOL[]

fields: [f-ht f-wt ans]
reset-fields: does [
    unfocus
    f-ht/text: " "   ; Changing this to "ENTER NUMBER HERE" does not help
    f-wt/text: " "
    focus f-ht
]

oncalc: does [ 
    ans/text: (to integer! f-wt/text) / ((100 * to integer! f-ht/text) * (100 * to integer! f-ht/text))
    show fields
]

lo: layout [
    style tx label 200x24 center
    style fld field 200x24 center
    style btn button 200x24 center

    tx "First Number:" 
    f-ht: fld 
    tx "Second Number:" 
    f-wt: fld 
    btn "Calculate" [oncalc]                   
    ans: tx "Answer"
    btn "Clear" [reset-fields show fields]     ; NOT WORKING- NOTHING HAPPENS
    btn "Exit" escape [unview/only lo]
]
reset-fields
view center-face lo

The GUI is showing all right. However, there are following problems:

On clear button clicking, nothing is happening.

There are no changes on GUI and no errors are being reported. Where is the problem and how can this be solved? Thanks for your help.


Solution

  • Clear the fields instead of setting to new strings

    reset-fields: does [
       unfocus
       clear f-ht/text  
       clear f-wt/text
       focus f-ht
    ]