text-list help required
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 ] ] ]
posted by: neuropsych 25-Aug-2024/8:44:59-7:00
Wow, this makes me realize how long it's been since I've worked with Rebol. I don't remember how to set this up properly, but creating a dummy list and showing that list by default will make the scroll function: repeat i 1000 [append dummydata:[] ""] search-list: text-list data dummydata [ ... Hopefully that's a useful workaround for the moment
posted by: Nick 27-Aug-2024/9:28:16-7:00
I should put a disclaimer on my tutorials to clarify that my position about using Rebol has changed, and that I now recommend other tools.
posted by: Nick 27-Aug-2024/9:31:59-7:00
Thanks Nick. Before you responded, I went through the posts in the forum and figured out that search-list/update works. Following is the complete working code for this app. 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,rebol.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 ;foreach record read-block [ ; print record ;] loaded: 1 ] search-names: func [query] [ if empty? trim query [return none] result-block: copy [] counter: 0 foreach record read-block [ counter: counter + 1 append result-block rejoin [counter " " (first parse/all record ",")] ] result-block2: copy [] if not query = "all" [ foreach record result-block [ if find/any record query [ append result-block2 record ] ] result-block: copy result-block2 ] return result-block ] display-contact: func [index] [ current-index: index rno/text: to-string current-index show rno temp: parse/all read-block/:current-index "," ;probe temp f1/text: temp/1 ;if f1/text = "-" [ ; current-index: current-index + 1 ; display-contact current-index ;] show f1 f2/text: temp/2 show f2 f3/text: temp/3 show f3 temp/4: replace/all temp/4 "" newline temp/4: replace/all temp/4 "" "," f4/text: temp/4 show f4 ] view center-face layout [ backcolor mint ;request-color ;box 707x3 white banner "Address Book" white ;box 707x3 white 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 search-list/update show search-list ] ] search-list: text-list [ if editOn = 1 [exit] breakOut: 0 current-index: to-integer first parse value " " display-contact current-index ] ] ; 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 text "Notes" f4: area 375 wrap return across btn "New" [ if loaded = 0 [exit] if editOn = 1 [exit] rno/text: to-string ((length? read-block) + 1) show rno clear-face f1 show f1 clear-face f2 show f2 clear-face f3 show f3 clear-face f4 show f4 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: "-"] if empty? trim f4/text [f4/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 "," temptext: replace/all f4/text newline "" temptext: replace/all f4/text "," "" append save-block temptext 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 display-contact length? read-block ] 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: "-"] if empty? trim f4/text [f4/text: "-"] updated-record: copy [] append updated-record f1/text append updated-record f2/text append updated-record f3/text temptext: replace/all f4/text newline "" temptext: replace/all f4/text "," "" append updated-record temptext read-block/:current-index: rejoin [updated-record/1 "," updated-record/2 "," updated-record/3 "," updated-record/4] write/lines %address-book.csv read-block alert "Record updated!" btn-editSave/size: 0x0 show btn-editSave btn-editCancel/size: 0x0 show btn-editCancel display-contact current-index ] 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 f4/text: "-" show f4 updated-record: copy [] append updated-record f1/text append updated-record f2/text append updated-record f3/text append updated-record f4/text read-block/:current-index: rejoin [updated-record/1 "," updated-record/2 "," updated-record/3 "," updated-record/4] 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 ] ] ] Regarding -> "I should put a disclaimer on my tutorials to clarify that my position about using Rebol has changed, and that I now recommend other tools." Yes, I have noticed that, however I want to learn REBOL well so that I can later understand Red well. Regards
posted by: neuropsych 27-Aug-2024/14:34:02-7:00
You motivated me to write a contacts example for https://learnsqlpage.com/sqlpage_quickstart.html simple version: http://server.py-thon.com:8008/contacts_simple.sql http://server.py-thon.com:8008/contacts_simple_no_comments.txt version with many features: http://server.py-thon.com:8008/contacts.sql http://server.py-thon.com:8008/contacts.txt Aside from all the nice features and the fact that this makes use of the most established database systems in the industry, which are compliant in almost any environment, to me, the ability to run apps like this on virtually any device (iOS, Android, Chromebook, Windows, Mac, Linux, Raspberry Pi, etc.), along with the multi-user nature of it, makes this platform absolutely rock solid. And the fact that so little code is required and so many of the most common features just work out of the box, and that everything about the system is easily extensible, all using the most prominent and established front-end and back-end technologies - all together make this hard to beat.
posted by: Nick 28-Aug-2024/22:14:02-7:00
Wow! Sql page does look very interesting. I would also like to give it a spin.
posted by: neuropsych 29-Aug-2024/11:02:11-7:00
|