Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

my-data

 [1/3] from: jim::clatfelter::net at: 21-Jul-2002 17:39


Hi Gregg, I'm just starting this script. I put the code I have so far at http://www.clatfelter.net/a-bookeep.r I put the January data at http://www.clatfelter.net/2002.exp The data are in lines like this: 7 fields, 1-Date, 2-Check# (if needed), 3-To, 4-For, and 3 fields (5, 6 and7) for expense categories. The last 3 are the ones I need totals for. That's why I was looping through the lines. I can loop through and print the contents of the field, but when I try to assign a value from the field (to total), it go to the wrong one. It goes to the date line (1) instead of the expense line (5) I am trying to total. It's the exact same code, but it goes to the wrong line on one and not on the other. I'm sure the loop is correct. This is the data order for the first two records: 01/02 Chevron Equip Gas 2.63 01/02 2488 Greenmark Fertilizer 22.41 button green "Calculate" [ for count 5 last-line rec-len if my-data/:count > to-string newline [ prin to-money my-data/:count prin " " ] ] total: 0 for count 5 last-line rec-len if my-data/:count > to-string newline [ total add total pick to-money my-data count ] ] ] Do I need to add probe? total add total probe pick to-money my-data count That doesn't solve the error. ** Script Error: Invalid argument: 01/02 (that's the first date on line 1. It should be line 5) ** Where: to-money ** Near: to money! :value Thanks for any help, Jim

 [2/3] from: greggirwin:mindspring at: 22-Jul-2002 11:14


Hi Jim, There are times when I like to spin through a text file and just do the work as I go. Most times, though, I tend to load the data into structures that I can work with more easily, especially in apps that have a UI of some kind as opposed to batch processing type apps. Anyway, I went a different direction because I didn't quite grok your example, so you can ignore this if it's not to your liking. ; Create a prototype object ; TO and FOR are keywords we don't want to conflict with exp-rec: make object! [ date: check-number: to*: for*: exp-1: exp-2: exp-3: none ] records: copy [] fields: next first exp-rec my-data: read/lines 02.exp ; Load the data into a block of objects. ; You could also just make a block of blocks if you want. foreach :fields my-data [ new-rec: make exp-rec [] new-rec/date: date new-rec/check-number: check-number new-rec/to*: to* new-rec/for*: for* new-rec/exp-1: to money! either not empty? exp-1 [exp-1][0] new-rec/exp-2: to money! either not empty? exp-2 [exp-2][0] new-rec/exp-3: to money! either not empty? exp-3 [exp-3][0] append records new-rec ] ; Now you can work with the objects to do whatever you want. total: $0.00 foreach rec records [ total: total + rec/exp-1 ] print total halt HTH! --Gregg

 [3/3] from: jim:clatfelter at: 22-Jul-2002 19:59


Hi Gregg, Thanks for the code and structure. I'm going to try it. I just used a text file because it's similar to a BASIC array, which I know how to manipulate already. I haven't yet caught on to REBOL's objects and blocks of objects and how to manipulate those. You've given me a start. Meanwhile, I managed to get the loop to work. Instead of putting all I wanted to do in one operation, I separated the assignment and the conversion to-money and the addition into three operations. Now everything adds up! button blue "Calculate" [ total: 0 total-exp-1: 0 for count 5 last-line rec-len [ if my-data/:count > to-string newline [ total: pick my-data count total: to-money total ] total-exp-1: total-exp-1 + total ] exp-1/text: total-exp-1 show [exp-1] ] Thanks again, Jim