Home   Archive   Permalink



creating fields in a layout

Hi,
I'm wondering what is wrong with the code that I have here. I want 9 fields to appear across the screen but I don't seem to be able to get them out of the block or string that they are in and append them to the layout. Here is the code:
R E B O L []
lo: [ across ]
    
for i 1 9 1 [
    repend lo [ rejoin ["fld" i ": " "field"]]    
]
    
view layout lo


posted by:   john     10-May-2014/23:58-7:00



>> repend lo [ to set-word! join "fld" 1 'field ]
== [fld1: field]

posted by:   Graham     11-May-2014/0:24:35-7:00



Hi Graham,
Thanks for that. But where can I find that in the documentation?

posted by:   John     11-May-2014/0:56:23-7:00



You have to understand what the difference between words and strings is.    
    
Something like
    
[ field1: ]
    
is a set-word! in a block. You can start with a word! or a string!
    
to set-word! 'field1
    
or
    
to set-word! "field1"
    


posted by:   Graham     11-May-2014/1:03:02-7:00



This is pretty foundational stuff. If you haven't read a book on programming in Rebol, I suggest you do so and get this (now) free book
    
http://www.lulu.com/shop/olivier-auverlot-and-peter-william-alfred-wood/rebol-a-programmers-guide/ebook/product-17515075.html

posted by:   Graham     11-May-2014/1:05:24-7:00



Thanks for the reference. Now I have expanded the program and would like it to create more rows but now my i variable does not have a value which I suppose is covered in the book. Here is the code. Perhaps you would be so kind as to tell me what the trouble is with the i variable? R E B O L []
lo: [ across space 0 ]
i:0
for j 1 20 1 [
    for k 1 9 1 [
        i: i + 1 [
            repend lo [to set-word! join "fld" i 'field 100]    
        ]
    ]
    repend lo 'return
]
    
view layout lo


posted by:   John     11-May-2014/1:24:57-7:00



[
     repend lo [to set-word! join "fld" i 'field 100]    
]
    
is just a block. You're not doing anything with it.
    
I suspect you want
    
for k 1 9 1 [
     repend lo [to set-word! join "fld" ++ i 'field 100]    
]

posted by:   Graham     11-May-2014/1:31:31-7:00



Yes that works like a million bucks. Thx
R E B O L []
lo: [ across space 0 ]
i: 0
for j 1 20 1 [
    for k 1 9 1 [
        i: i + 1
        repend lo [to set-word! join "fld" i 'field 100]    
        ]
    repend lo 'return
]
    
view layout lo


posted by:   john     11-May-2014/1:38:54-7:00



Hi
If Graham or Nick or anyone could answer this, I hope it will be instructive. When Graham suggested ++ i, instead of i: i + 1 he was assuming a fuction:
++: func ['word] [set word 1 + get word]
Of course, that works but why? I assumed you could write a function as follows:
++ func [num] [num: num + 1] .
That does NOT work over the function suggested by Graham. But why? Thx for any help.


posted by:   John     11-May-2014/17:20:43-7:00



'num is a local variable in the function. It doesn't change the value of the word outside that context.
    


posted by:   Nick     11-May-2014/20:47:22-7:00