I have started learning Rebol R2 based on the videos of books made by Nick. I have developed a simple database as a proof of concept of my learning. I am having problem with the text-list [search-list] in this program. The scroll function on the text-list is not working. Please guide.
R E B O L [title: "Address Book - AnikaSOFT 2024"]
save-block: copy []
read-block: copy []
current-index: 0
loaded: 0
editOn: 0
firstRun: 1
; Function to create the address-book.csv file with a dummy record if it doesn't exist
init-address-book: does [
if not exists? %address-book.csv [
write %address-book.csv "John Doe,555-1234,john.doe@example.com^/"
]
]
load-data: does [
if firstRun [
init-address-book ; Ensure the file is initialized
write/binary %backup.csv read %address-book.csv
firstRun: 0
]
read-block: copy []
read-block: read/lines %address-book.csv
loaded: 1
]
search-names: func [query] [
if empty? trim query [return none]
result-block: copy []
either (trim query) = "all" [
foreach record read-block [
append result-block first parse record ","
]
][
foreach record read-block [
if find/any record query [
append result-block first parse record ","
]
]
]
return result-block
]
display-contact: func [index] [
current-index: index
rno/text: to-string current-index
show rno
temp: parse read-block/:current-index ","
f1/text: temp/1
show f1
f2/text: temp/2
show f2
f3/text: temp/3
show f3
]
view center-face layout [
backcolor mint
across ; Arrange panes side by side
; Left Pane
left-pane: panel 250x400 gold [
origin 10x10
below
btn "Load" [
if loaded = 1 [exit]
load-data
current-index: 1
display-contact current-index
]
text "Search by Name:"
search-field: field "" 200
btn "Search" [
if loaded = 0 [exit]
if editOn = 1 [exit]
results: search-names search-field/text
either none? results [
alert "No results found."
][
search-list/data: results
show search-list
]
]
search-list: text-list [
if editOn = 1 [exit]
foreach record read-block [
if find/part record value length? value [
current-index: index? find read-block record
;print current-index
display-contact current-index
[break]
]
]
]
]
; Right Pane
right-pane: panel 450x400 gold [
origin 5x5
below
across
text "Name" f1: field return
text "Phone" f2: field return
text "Email" f3: field return
across
btn "New" [
if loaded = 0 [exit]
if editOn = 1 [exit]
rno/text: to-string ((length? read-block) + 1)
show rno
f1/text: ""
show f1
f2/text: ""
show f2
f3/text: ""
show f3
btn-save/size: 43x22
show btn-save
btn-cancel/size: 43x22
show btn-cancel
editOn: 1
]
btn-save: btn "Save" [
save-block: copy []
if empty? trim f1/text [f1/text: "-"]
if empty? trim f2/text [f2/text: "-"]
if empty? trim f3/text [f3/text: "-"]
append save-block f1/text
append save-block ","
append save-block f2/text
append save-block ","
append save-block f3/text
append save-block newline
write/binary/append %address-book.csv save-block
alert "Saved"
load-data
btn-save/size: 0x0
show btn-save
btn-cancel/size: 0x0
show btn-cancel
editOn: 0
]
btn-cancel: btn "Cancel" [
btn-cancel/size: 0x0
show btn-cancel
btn-save/size: 0x0
show btn-save
editOn: 0
display-contact current-index
]
do [
btn-save/size: 0x0
btn-cancel/size: 0x0
]
btn-edit: btn "Edit" [
if loaded = 0 [exit]
if editOn = 1 [exit]
btn-editSave/size: 43x22
show btn-editSave
btn-editCancel/Size: 43x22
show btn-editCancel
editOn: 1
]
btn-editSave: btn "Save" [
editOn: 0
if empty? trim f1/text [f1/text: "-"]
if empty? trim f2/text [f2/text: "-"]
if empty? trim f3/text [f3/text: "-"]
updated-record: copy []
append updated-record f1/text
append updated-record f2/text
append updated-record f3/text
read-block/:current-index: rejoin [updated-record/1 "," updated-record/2 "," updated-record/3]
write/lines %address-book.csv read-block
alert "Record updated!"
btn-editSave/size: 0x0
show btn-editSave
btn-editCancel/size: 0x0
show btn-editCancel
]
btn-editCancel: btn "Cancel" [
btn-editCancel/size: 0x0
show btn-editCancel
btn-editSave/size: 0x0
show btn-editSave
editOn: 0
display-contact current-index
]
do [
btn-editSave/size: 0x0
btn-editCancel/size: 0x0
]
btn-delete: btn "Delete" [
if loaded = 0 [exit]
if editOn = 1 [exit]
temp: do [request "Really want to delete?"]
if not temp [exit]
f1/text: "-"
show f1
f2/text: "-"
show f2
f3/text: "-"
show f3
updated-record: copy []
append updated-record f1/text
append updated-record f2/text
append updated-record f3/text
read-block/:current-index: rejoin [updated-record/1 "," updated-record/2 "," updated-record/3]
write/lines %address-book.csv read-block
alert "Record deleted!"
]
return
across
btn "First" [
if loaded = 0 [exit]
if editOn = 1 [exit]
current-index: 1
display-contact current-index
]
btnPrev: btn "Prev" [
if loaded = 0 [exit]
if editOn = 1 [exit]
if current-index > 1 [
current-index: current-index - 1
display-contact current-index
]
]
; {key keycode [left] [
; do-face btnPrev 1
;]}
rno: field to-string current-index 30
btnNext: btn "Next" [
if loaded = 0 [exit]
if editOn = 1 [exit]
if current-index < length? read-block [
current-index: current-index + 1
display-contact current-index
]
]
;{key keycode [right] [
; do-face btnNext 1
;]}
btn "Last" [
if loaded = 0 [exit]
if editOn = 1 [exit]
current-index: length? read-block
display-contact current-index
]
]
]