Search code examples
user-interfacevariable-assignmentrebolred-lang

Load values from a list in Red language


I am trying following code to read values from a list to be put into field elements which are also placed in another list:

Red [needs: view]

view [
    text "N1:"
    ff: field ""
    text "N2:"
    gg: field ""

    do [fldlist: [ff gg] 
        vv: 5  ww: 10
        varlist: [vv ww]   ]

    button "Click" [
        repeat i (length? varlist) 
            [to-set-path to-word fldlist/i/text:  varlist/:i]  ] ]

However, it is not working. The error is:

*** Script Error: path fldlist/i/text: is not valid for none! type
*** Where: set-path
*** Stack: view do-events do-actor do-safe to-set-path to-word 

I also tried :i (i) and (:i) instead of just i but it is not working. Where is the problem and how can it be solved? Thanks for your help.


Solution

  • Use

     button "Click" [
        repeat i (length? varlist)   [
            tmp: get fldlist/:i
            tmp/text:  form get varlist/:i
        ]  
    ]
    

    I think, you should start to read some documentation about the concepts of Red and Rebol and/or just debug the code in the console.

    Update

    I have to concede, that in this regards Red does not behave as I was expecting from Rebol experience. But I got another tricky solution without temporary words.

    button "Click" [
        repeat i (length? varlist) [
            set first find words-of get fldlist/:i  'text form get varlist/:i
        ]  
    ]