home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 19.18 Employee array example
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
-
- LOCAL mdept:=space(6)
- PRIVATE employees:={}
- use EMPLOYEE new index DEPT_ORD
- @ 2,6 get mdept pict "!!!!!!"
- setcursor(1)
- read
- if lastkey() <> 27
- seek mdept
- while !eof() .and. EMPLOYEE->dept_id = mdept
- Aadd(employees,full_name+" "+dtoc(hired)+" "+;
- str(salary,12,2)+" "+str(recno(),6) )
- skip +1
- enddo
- endif
-
-
-
- // The variables keepgoing, elt, and pos will be updated
- // by the A_UDF called from ACHOICE. As a result, they
- // must be declared as PRIVATE rather than LOCAL.
-
- LOCAL x,mname,mdate,mamt,mrow,mrec
- PRIVATE keepgoing := .T.,elt:=1,pos:=0,tags[len(employees)]
- afill(tags,.T.)
- while keepgoing
- x :=achoice(6,15,22,65,employees,tags,"A_UDF",elt,pos)
- if x > 0
- mname := substr(employees[x],1,25)
- mdate := ctod(substr(employees[x],28,8))
- mamt := val(substr(employees[x],37,12))
- mrec := val(right(employees[x],6))
- mrow := row()
- @ mrow,15 get mname
- @ mrow,42 get mdate
- @ mrow,51 get mamt
- read
- if lastkey() <> 27
- select EMPLOYEE
- goto mrec
- replace EMPLOYEE->full_name with mname,;
- EMPLOYEE->hired with mdate,;
- EMPLOYEE->salary with mamt
- employees[x] :=mname+" "+dtoc(mdate)+" "+;
- str(mamt,12,2)+" "+str(mrec,6)
- endif
- endif
- enddo
-
-
- function a_udf(mode,element,position)
- LOCAL lk:=lastkey()
- #include "ACHOICE.CH"
- #include "INKEY.CH"
-
- // Private variables ELT,POS, and KEEPGOING are
- // passed from the program containing the ACHOICE
- // function call.
-
- elt := element // update element
- pos := position // and position
- if mode = AC_EXCEPT // Keystroke exception
- do case
- case lk = K_ESC // ESCAPE key
- keepgoing = .f. // Tell LOOP to exit
- return AC_ABORT
- case lk = 13 .or. lk = 32 // ENTER or space
- return AC_SELECT
- case chr(lk)$"Ss" // Sort array
- sort_it()
- return AC_ABORT
- case chr(lk)$"Ff" // Find an item
- find_it()
- return AC_ABORT
- endcase
- endif
- return AC_CONT
-
- function sort_it
- LOCAL which:=1
- @ 6,15 clear to 22,65
- @ 6,15 prompt "Name"
- @ 6,43 prompt "Date"
- @ 6,52 prompt "Salary"
- menu to which
- do case
- case which = 1
- asort(employees)
- case which = 2
- asort(employees,,,{|x,y|substr(x,28,8)<substr(y,28,8)} )
- case which = 3
- asort(employees,,,{|x,y|substr(x,37,12)<substr(y,37,12)} )
- endcase
- return NIL
-
- function find_it
- LOCAL mname:=space(25),myear:=year(date())
- LOCAL mop_code :="<",mamt:=0.0,jj,tag_me,find_one:=.F.
- @ 6,15 clear to 22,65
- @ 6,15 get mname
- @ 6,48 get myear pict "99"
- @ 6,51 get mop_code pict "!" ;
- valid mop_code $"<>= " .or. lastkey() = K_UP
- @ 6,52 get mamt pict "999999.99"
- read
- afill(tags,.F.)
- for jj=1 to len(tags)
- tag_me := .t.
- if !empty( mname )
- tag_me := (upper(mname) $ upper(substr(employees[jj],1,25)))
- endif
- if !empty( myear )
- tag_me := (year(ctod(substr(employees[jj],28,8)))=myear)
- endif
- if !empty( mamt )
- x := val(substr(employees[jj],37,12))
- do case
- case mop_code = "<"
- tag_me := (x<mamt)
- case mop_code = "="
- tag_me := (x=mamt)
- case mop_code = ">"
- tag_me := (x>mamt)
- endcase
- endif
- tags[jj] := tag_me
- if tag_me
- find_one :=.T.
- endif
- next
- if !find_one
- afill(tags,.T.)
- endif
- return NIL
-