forum-msg-id-135096-edit

Original date:2020-10-05 10:29:58 Edited by: Senator Subject: Re: Budget Builder

----------------------- beginning  of register.ex part 2 
------------------------------------------------------------- 
procedure add_record() -- add a new record to the current table 
object key, data, note  
integer rec, t -- t = transaction type debit/deposit 
atom amt, bal 
sequence prompt 
    current_table = db_current_table() 
    if equal(current_table, BUDGET) then  -- table: BUDGET 
        key = set_budget_key()            -- obtain key - enter day of month for  
        rec = db_find_key(key)            -- BUDGET deposit/debit transaction 
    else                                  -- table: REGISTER/CASH 
        key = dt_menu(SECOND) --,USE_MENU)    -- enter full datetime value 
        rec = db_find_key(key) 
        if is_error(rec) then return end if 
        -- if rec > 0, then key already exists within database add 30 seconds to key and try again 
        if rec then  
            loop do  
                key=datetime:add(key,30,SECONDS)  
                rec = db_find_key(key) 
            until rec < 0 
            end loop 
        end if 
    end if 
    t = debit_or_deposit()   
    if t = 0 then return end if 
    -- convert rec to a positive value in order to calculate current balance before insertion of next record  
    bal=balance(-rec-1) -- balance before insertion of current record  
    data = {} 
    for i = 2 to 3 do -- FIELDS[1] = key 
        prompt = "\t" & FIELDS[i] 
        if i = 2 then -- FIELDS[2] = Transaction Note: 
            note = prompt_string(prompt) data = append(data, note) 
        else           -- FIELDS[3] = "$" 
            if t = -1 then set_foreground_color(RED)  
            else           set_foreground_color(FGC)  
            end if 
            amt  = prompt_number(prompt,{})-- amt is an atom  -- 23.46 
            amt *= 100 -- amt now expressed as an integer      -- 2346 
            amt *= t    
            bal += amt   
            data = append(data, amt)  
        end if 
    end for 
    if db_insert(key, data) != DB_OK then any_key("\n\tinsert failed!\n") return end if  
list() 
end procedure 
 
procedure delete_record() 
integer rec 
    list() 
    rec = prompt_number("\n\n\tEnter # of db record to delete: ",{1,db_table_size()}) 
    puts(1,"\n\n") 
    display_full_note(rec) 
    set_foreground_color(RED) 
    puts(SCREEN, "\n\n\tDelete? (y/n) ") 
    if find('n', gets(0)) then  
            set_foreground_color(FGC)  
    else     
            db_delete_record(rec) 
            set_foreground_color(FGC) 
    end if 
list() 
end procedure 
 
-- list current month, or prior=1 for previous month 
procedure list_month(integer prior = 0)  
datetime dt 
    if find(db_current_table(), {REGISTER,CASH}) then 
        dt = now()   list(dt[YEAR],dt[MONTH]-prior) 
    end if 
end procedure 
----------------------- end of register.ex part 2 
-------------------------------------------------------- 
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu