|
Pages: [1]
|
 |
|
Author
|
Topic: Basic variable help (Read 416 times)
|
|
Rebol Rookie
|
Hi I have just started to learn to program with Rebol, but I am struggling to understand the basics. I can set up forms okay, but when it comes to making things happen . . .problem! I have searched the internet and looked at several sample programs, but can't find anything simple enough to understand on variables and displaying input on the GUI. So if someone can show how to do the following basic steps, perhaps I can build on that. So could someone please provide a simple sample code for the following; Input text from the screen (say someones name) Store that name as a variable. display that variable back onto the screen. Note:I am using Crimson Editor for my programming. Any help would be greatly appreciated. thanks, Rebol Rookie
|
|
|
|
|
Logged
|
|
|
|
|
henrikmk
|
OK, some basic things you need to know about VID:
Whenever you create an element such as a field, a text label, an image or something else, VID creates a face, which is an object that contains certain information about color, text content. It also contains accessors to getting and setting values for the face, such as what text to display or value you want to get from the face. Faces can be nested in other faces. Faces can therefore be big trees of objects. Type this example in the console:
layout [f: field]
This creates a face with another face inside it that is configured as a field. If you were to display this, you'd see a window with a field in it. In fact the window itself is the root face for this layout. You are allowed to access the field face using the 'f word, because that was written before describing the 'field word.
Now in the console, if you type "f" and press enter, you'll get an object returned. If you type:
? f
You get the content of the field face. That's the inner workings of the field. You can then access various parts of the field by saying things like:
f/size f/text f/color
etc., just like you would, when accessing a normal object.
In VID, each face type is called a style. That means a field is one style and box is another style, but they both have the same basic structure. They just have different values inside, and the 'view function renders them on screen according to those values.
Now to make things more easy and organized, each face has accessors, i.e. methods for getting data in and out of them in a correct fashion, so you don't have to worry about redisplaying the face after setting a new value or worry about the datatype being incorrect for the face in most cases. These accessors are individual for the face style. Not all faces have accessors.
Now try the first example again, but this time with 'view in front of it, so a window opens:
view layout [f: field]
Now make the console active and press escape, so you can get back to work on the console without closing the window. The window can now be manipulated via REBOL code interactively.
Try typing:
set-face f "hello" set-face f "world" get-face f set-face/no-show f "no change appears" get-face f
I think you get the idea.
You can return to using the window again, by typing "do-events". If you don't want to do that, close the window by typing "unview".
'set-face and 'get-face work also on the panel style, which means you can get and set multiple fields grouped together in panels. Let's try the previous example again, now with a panel of fields:
view layout [p: panel [field field field]]
Escape to console like before. Now to set all fields, you need to feed 'p with a block of values:
set-face p ["a" "b" "c"] set-face p [1 2 3] get-face p set-face p [7 8] set-face p ["eenie" "meenie" "miney" "mo"] get-face p
I hope you get the idea. There's a bit more, but I'll let you try this first. Then we can proceed later.
|
|
|
|
|
Logged
|
|
|
|
DefiantPc
Administrator
Jr. Member
Offline
Posts: 70
|
|
|
|
|
|
Logged
|
|
|
|
|
Rebol Rookie
|
Thank you both for your quick response. I had already looked at http://musiclessonz.com/rebol_tutorial.html but didn't grasp the basics from it. Although the tutorial had a lot of useful advice on other areas. Thank you henrikmk for taking the time and trouble to provide the tutorial. I found it very helpful and can follow the examples you set out on the console. But when it comes to writing the code into my program, I haven't quite got it. I can produce the field on my layout, but I still can not get the information input from the text field into a variable and then display it on the layout. Again, any help and assistance on this would be most welcome.
Thanks
Rebol Rookie
|
|
|
|
|
Logged
|
|
|
|
|
henrikmk
|
OK, I wanted to avoid exactly that topic to "force" you to learn the other principles first, because they are relevant here. Now that you have that, let's move to the real deal:
Faces can have actions, which are stated as blocks in the layout code. You've probably tried something like:
view layout [b: button "Hello" [print "hello"]]
and found that "hello" is printed in the console every time you click the button. The block is referred to as 'action in the face object for many styles.
You can run this action manually using 'do-face:
do-face b none
The none! indicates a parameter, but since we don't need it here, the parameter is just none. The importance of 'do-face comes into play as it's used everywhere you need to run the action for the face. The action is not actually stored as a block, but as a function. If you take a look at the 'b face, you'll see something like:
>> probe get in b 'action == func [face value][print "hello"]
This means you can use the words 'face and 'value in the action block. 'face refers to the face object itself, which means you can access any aspect of the face from within the action block, such as by using face/text or face/flags. 'value holds the value that can be gotten with 'get-face, outside the layout, as we saw in my first post. We can then look at a field example (this is what you wanted all along):
view layout [field [print value]]
The action for the 'field style is run every time you tab out of the field, when you press return or when you unfocus it with the mouse.
If you simply want to store the value, just use something like:
view layout [f: field [my-value: value]]
I'm sorry if the route to your desired information was a bit convoluted to explain this, but I'm doing it to give you encouragement to explore VID and REBOL from the console, and I've here shown you some pretty powerful tools to conduct that exploration.
|
|
|
|
|
Logged
|
|
|
|
|
Rebol Rookie
|
Thanks again henrikmk,
The tutorials are great - the more information I get the better. In spite of your excellent explanation, I still find it difficult to comprehend. But I will study it closely over the next few days and hopefully it will all come together.
Any more advice on this would still be very welcome.
Thanks,
Rebol Rookie
|
|
|
|
|
Logged
|
|
|
|
|
notchent
|
Hi Rebol Rookie, Here's a simple answer to your first question: rebol []
view layout [ f: field btn "Display Variable" [ t: f/text alert t ] ] You can assign a word label (variable) to just about anything in Rebol, using the colon symbol. In the above example, the variable "f" is assigned to the GUI field, then the variable "t" is assigned to the text contained in that field. Here's another example, just a little bit more complicated: rebol []
view layout [ f1: field btn "Display Variable" [ t: f1/text f2/text: t show f2 ] f2: field ] In that example, "t" is assigned the text contained in the f1 field, then the text in f2 is set to "t" - again, all using the colon symbol (and then the display is updated with the "show" function - that's easy to forget, and perhaps part of your troubles?). Does that help? You might find the tutorial at http://musiclessonz.com/rebol.html a bit quicker to grasp - it's shorter then the original full tutorial. If you read it completely (and especially the example code), things like this should start to become pretty intuitive 
|
|
|
|
« Last Edit: August 10, 2008, 09:35:27 PM by notchent »
|
Logged
|
|
|
|
|
Rebol Rookie
|
Thank you Notchent,
This is exactly what I want!
Also, thanks to everybody for your help - much appreciated.
Rebol Rookie
|
|
|
|
|
Logged
|
|
|
|
|
btiffin
|
Rebol Rookie; Nick is one of the REBOL unsung heroes. Nick; Thanks for all the goodies.  Cheers, Brian
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2292 Posts in 593 Topics by 3742 Members
Latest Member: CorHorgeExpex
|