
In previous installments, we learnt how to create a Visual GUI in Rebol and how to create a Mini-Text Database, now we’ll combine the two: How to bind a Text Database to a Visual Form. I have much difficulty as newbie to find any tutorial for the absolute beginner, that’s why I wrote this one and hope you will enjoy it.

Start the Console. After loading the text-database with this instruction:
db: load %db.txt
let’s add a Window layout:
counter: 1
window: layout [
h2 "Account Information"
text "Please enter your account details here."
across
label "First name" tab FN: field db/:counter/1
return
label "Last name" tab LN: field db/:counter/2
return
label "Email" tab Em: field db/:counter/3
return
tab button "Save" [btn-save]
button "Next" [btn-next]
return
tab button "Close" [btn-close]
button "Previous" [btn-previous]
]
btn-save: func[][
print "save not yet implemented"
]
btn-next: func[][
print "next not yet implemented"
]
btn-previous: func[][
print "previous not yet implemented"
]
btn-close: func[][
print "close not yet implemented"
]
Change btn-save implementation:
btn-save: func[][
db/:counter/1: FN/text
db/:counter/2: LN/text
db/:counter/3: Em/text
]
view window
Change btn-next and btn-previous implementation:
btn-next: func[][
if (counter < (length? db)) [
counter: counter + 1
FN/text: db/:counter/1
LN/text: db/:counter/2
Em/text: db/:counter/3
show window
]
]
btn-previous: func[][
if (counter > 1) [
counter: counter - 1
FN/text: db/:counter/1
LN/text: db/:counter/2
Em/text: db/:counter/3
show window
]
]
view window
Change btn-close implementation:
btn-close: func[][
Unview
]
view window
Last but not least we also need 2 more buttons btn-add and btn-delete:
btn-add: func[][
FN/text: ""
LN/text: ""
Em/text: ""
show window
counter: (length? db) + 1
append db to-block remold [FN/text LN/text Em/text]
]
btn-delete: func[][
remove db counter
Switch counter
[
1 [
counter: counter - 1
FN/text: ""
LN/text: ""
Em/text: ""
]
] /default [
counter: counter - 1
FN/text: db/:counter/1
LN/text: db/:counter/2
Em/text: db/:counter/3
]
show window
]
window: layout [
h2 "Account Information"
text "Please enter your account details here."
across
label "First name" tab FN: field db/:counter/1
return
label "Last name" tab LN: field db/:counter/2
return
label "Email" tab Em: field db/:counter/3
return
button "Add" [btn-add]
button "Save" [btn-save]
button "Next" [btn-next]
return
button "Delete" [btn-delete]
button "Close" [btn-close]
button "Previous" [btn-previous]
]
Update July 5th: As kc puts it (see comment at the end) you can replace
append db to-block remold [FN/text LN/text Em/text]
by
append/only remold [FN/text LN/text Em/text]
This is the whole program:
Rebol[
title: "Rebol Mini-Text Database with Visual GUI"
author: "http://reboltutorial.com/blog/rebol-mini-text-database/"
version: 1.0.0
]
db: [["John" "Doe" "email hidden; JavaScript is required"]["Jane" "Doe" "email hidden; JavaScript is required"]]
counter: 1
window: layout [
h2 "Account Information"
text "Please enter your account details here."
across
label "First name" tab FN: field db/:counter/1
return
label "Last name" tab LN: field db/:counter/2
return
label "Email" tab Em: field db/:counter/3
return
button "Add" [btn-add]
button "Save" [btn-save]
button "Next" [btn-next]
return
button "Delete" [btn-delete]
button "Close" [btn-close]
button "Previous" [btn-previous]
]
btn-save: func[][
db/:counter/1: FN/text
db/:counter/2: LN/text
db/:counter/3: Em/text
]
btn-next: func[][
if (counter < (length? db)) [
counter: counter + 1
FN/text: db/:counter/1
LN/text: db/:counter/2
Em/text: db/:counter/3
show window
]
]
btn-previous: func[][
if (counter > 1) [
counter: counter - 1
FN/text: db/:counter/1
LN/text: db/:counter/2
Em/text: db/:counter/3
show window
]
]
btn-add: func[][
FN/text: ""
LN/text: ""
Em/text: ""
show window
counter: (length? db) + 1
append db to-block remold [FN/text LN/text Em/text]
]
btn-delete: func[][
remove db counter
Switch counter
[
1 [
counter: counter - 1
FN/text: ""
LN/text: ""
Em/text: ""
]
] /default [
counter: counter - 1
FN/text: db/:counter/1
LN/text: db/:counter/2
Em/text: db/:counter/3
]
show window
]
btn-close: func[][
Unview
]
view/title window "Mini-Text Database"
If you want to add sort or find functions see here.
References:















Nice tutorial. I’ve looked at Rebol for a while. Would you say it’s useful to learn Rebol 2 knowing there is a version 3 not far away?
append/only will add blocks to a block
@crex sure, why do you want to wait ? The more you wait the more you will be missing all that you can already do with version 2
@kc thanks, I’m still a beginner myself so every advice welcomed !
GREAT site!
Database could be made easily also with the “to-tag” function.
It helps to subdivide data and find them, here an example to find a page of a personal diary:
find_data: func [date_I_search] [
; diary is our database
temp1: to-tag date_I_search
parse diary [thru temp1 copy what_I_want to ]
return what_I_want
]
GREAT site!
Database could be made easily also with the “to-tag” function.
It helps to subdivide data and find them, here an example to find a page of a personal diary:
find_data: func [date_I_search] [
; diary is our database
temp1: to-tag date_I_search
parse diary [thru temp1 copy what_I_want to ]
return what_I_want
]
Sorry but comments can’t display “” after
parse diary [thru temp1 copy what_I_want to
Sorry max for the trouble, can you send your program by email to reboltutorial @ yahoo.com or maybe you can contribute to reboltutorial.com ?