home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / database / 5762 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.8 KB

  1. Path: sparky!uunet!caen!uakari.primate.wisc.edu!zazen!news
  2. From: dly@vms.macc.wisc.edu
  3. Newsgroups: comp.databases
  4. Subject: PARADOX, procedure to calculate median
  5. Message-ID: <1992Jul23.145939.21048@macc.wisc.edu>
  6. Date: 23 Jul 92 14:56:35 GMT
  7. Sender: news@macc.wisc.edu (USENET News System)
  8. Organization: University of Wisconsin Academic Computing Center
  9. Lines: 60
  10.  
  11. I am new to PARADOX, and I needed to figure out a way that users could
  12. have a median on a numeric column calculated for them.  I came up with
  13. this procedure which works, but it is very BRUTE force.  If there are 
  14. other users who have ideas on how to streamline this, please let me know.
  15.  
  16. Thanks!
  17. Debbie Yoshihara
  18. DLY@MACC.WISC.EDU
  19.  
  20. 1) First I set up SHIFT-F1 in a miniscript:
  21.    SETKEY "F11" PLAY "MEDIAN"
  22.  
  23. 2) Then VIEW a table, and TAB to the field where you would like a median
  24.    and press SHIFT-F1
  25.  
  26. 3) The results will be shown in the ANSWER table.
  27.  
  28. 4) Here is the Procedure:
  29.  
  30. PROC MEDIAN(TBLNAME,FLDNAME)
  31.  IF FIELDTYPE() <> "N" THEN
  32.    MESSAGE "ERROR IN PROCESSING: You must select a numeric field!"
  33.    SLEEP 2000
  34.    RETURN 
  35.  ENDIF
  36.  IF FLDNAME = "#" THEN
  37.    MESSAGE "ERROR IN PROCESSING: You cannot select the # field!"
  38.    SLEEP 2000
  39.    RETURN 
  40.  ENDIF
  41.  SORT TBLNAME ON FLDNAME TO "ZZZTEMP"
  42.  HOWMANY  = CCOUNT("ZZZTEMP",FLDNAME)
  43.  MIDPLACE = HOWMANY/2
  44.  MODVAL   = MOD(HOWMANY,2)
  45.  EDIT "ZZZTEMP"
  46.  MOVETO RECORD MIDPLACE
  47.  MOVETO FIELD FLDNAME
  48.  VALUE1 = []
  49.  MOVETO RECORD MIDPLACE+1
  50.  MOVETO FIELD FLDNAME
  51.  VALUE2 = []
  52.  DO_IT!
  53.  DELETE "ZZZTEMP"
  54.  DO_IT!
  55.  NEWFLD =  "MEDIAN OF " + FLDNAME
  56.  CREATE "ANSWER" NEWFLD : "N"
  57.  EDIT "ANSWER"
  58.  MOVETO FIELD NEWFLD
  59.  IF MODVAL=0 THEN
  60.    [ANSWER -> ] = (VALUE1+VALUE2)/2
  61.  ELSE
  62.    [ANSWER -> ] = VALUE1 
  63.  ENDIF
  64.  DO_IT!
  65.  RETURN 
  66. ENDPROC
  67.  
  68. TBLNAME = TABLE()
  69. FLDNAME = FIELD()
  70. MEDIAN(TBLNAME,FLDNAME)
  71.