entering, storing and retrieving data in an array
[1/3] from: meta:dimensional at: 21-Apr-2001 8:53
Can anyone point me to the best place to learn about creating a REBOL/View application for entering, storing and retrieving data in an array? As an example, how would I create an app where I could enter the names, songs and categories of music CDs, and then sort and search it by name, song or category? I'm picturing an interface with a list that scrolls through all CDs, fields for editing the currently selected entry or entering a new entry, a search field and some way to select the array member for sorting. My current stumbling block is trying to understand the loop structure for adding data to an array block. Pointers to good examples of similar scripts would be most appreciated. Thanks, -Jamie
[2/3] from: jeff:rebol at: 21-Apr-2001 9:18
Howdy, Jamie: Below is an example of ONE way to do that. The editing of entries can be handled by supplying action blocks for each item inside the LIST layout. Lemme know if that doesn't make sense and I'll post an example of that later. This is one way to do it, where you handle the SUPPLY function for the LIST. -jeff
> Can anyone point me to the best place to learn about > creating a REBOL/View application for entering, storing and
<<quoted lines omitted: 11>>> Thanks, > -Jamie
REBOL [ Title: "Ordered Table Example" Author: "Jeff Kreis" Date: 21-Apr-2001 Purpose: "Shows a way to make a dynamic table" Comment: "Data is maintained outside of the widget" ] ;- Drop everything into a separate ; context. Helps keep words from ; going global context [ ;- This returns a block that has ; a different compare function for ; sorting our data each time and ; then showing the list again ; [ Saves typing (; ] sfun: func [num][ compose/deep [sort/compare tdata func [a b][ (to-path reduce ['a num]) < (to-path reduce ['b num])] show tbl ] ] ;- The database tdata: [ ["Q" 1-Apr-2001 $50] ["Z" 15-Dec-1952 $15] ["A" 4-Jul-1776 $11] ] ;- For the scroll bar cnt: 0 view layout [ backdrop 150.160.190 across ;- These buttons change the ordering button "1" (sfun 1) button "2" (sfun 2) button "3" (sfun 3) return ;- LIST takes a layout for how to place items ; and uses an iterated pane to fill those items ; as needed. tbl: list 300x400 [across space 0 text 100 text 100 text 100] ;- SUPPLY: This takes the following block and ; uses this with our LIST as the iterated pane ; function. This function is called each time ; for each virtual face with this signature: ; FUNC [FACE COUNT INDEX] .. We use the count ; and index to determine what text should be ; shown in each face position and what color ; to make each row. The supply function also ; deals with the scroll bar which changes the ; offset into the data that we are looking. ; -- IMPORTANT: When you are in an iterated ; pane function, do not call SHOW. Just set the ; facets of the virtual face and exit when done. supply [ count: count + cnt face/color: ivory face/text: none if even? count [face/color: ivory - 50.50.50] if none? v: pick tdata count [exit] face/text: pick v index ] sld: slider 16x400 [ c: max 0 to-integer (length? tdata) * value if c <> cnt [cnt: c show tbl] ] return label "New data row:" return ;- We just punt on data entry. They have to ; enter the stuff in the proper format ; (string, data, money) or it will pop an ; error dialog. field 300 [ if error? try [ v: parse face/text none repend/only tdata [v/1 to-date v/2 to-money v/3] show tbl ][request/ok "OUCH! ERROR!!"] clear face/text show face ] ] ]
[3/3] from: meta:dimensional at: 21-Apr-2001 13:17
Thanks for your quick feedback, Jeff! [jeff--rebol--net] wrote:
> Howdy, Jamie: > > Below is an example of ONE way to do that. The editing of > entries can be handled by supplying action blocks for each > item inside the LIST layout. Lemme know if that doesn't > make sense and I'll post an example of that later.
Just FYI I'm a complete REBOL newbie. I think in English and not C++. I'm looking to create the most human-readable code possible. I wrote the docs for HyperSense on the NeXT and have written fairly sophisticated apps with CanDo on the Amiga, which may give you a hint of where I'm coming from. I'm hoping I can write english-like scripts with REBOL to get useful things done across multiple platforms quickly. I've looked for answers in the various documents available from rebol.com and tried to deconstruct script examples. I've learned a bit but haven't gotten a handle on adding and subtracting data from arrays. I really appreciate your example and am trying to figure it out. So far I can identify what happens in each part of the script but I'm not yet completely understanding how it is happening. It looks clever, though and the comments help. For my first very simple app, there are some differences. Distilling it to the basics: I want to be able to click within the list area to hilight one record. Is there a REBOL list style that does that? I want separate entry fields for each bit of data in the record. When I click on a record in the list I want the entry fields to show the data for the selected record so they can be edited. I want a button for adding a new record. I want a button for saving the database to a file. It could load the file automatically when the REBOL script is started. I shouldn't have mentioned sorting yet, until I get a handle on this very basic database handling. Any further hints or dead simple examples most appreciated. Here's my first whack: REBOL [Title: "CD List"] CDName: "CD Name" Song: "Song Name" Style: "Music Style" CD: make object! [CDName Song Style] view layout [ backdrop effect [gradient 60.0.150 60.10.60] across Button "Add Song" Button "Remove Song" Button "Save Songs" below across space 85x0 vh4 "CD" vh4 "Song" vh4 "Style" below space 3x3 list 380x65 [ origin 0 across text 110 text 115 text 110 ] data [ [:CDName :Song :Style] ] below across field 120 :CDName field 120 :Song field 120 :Style ] This shows the basic interface I want. I don't yet have an array setup to store multiple records (the CD object is intended for that) or any wiring for the buttons to add a record (Add Song), remove the selected record (Remove Song) and save the entire database to a file (Save Songs). I'm looking for hints on how to do this in the most easily understandable English-like way (not necessarily the most programmer-elegant way). Curiosity: The variables I use, CDName, Song and Style, are picked up by the fields but not the list. The "list" face currently does not allow selecting of a record. Hope I'm using the REBOL jargon correctly. Again, I'm very new to REBOL but am really excited by what REBOL might allow me to do. This first project is just to get my feet wet. Thanks for any and all comments! :^) Cheers, -Jamie
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted