In a population of SAT scores, how does one go about determining the median value? Simple table structure, no links, field containing Verbal, Math and Percentiles. One column for each.
Thankyou
Thankyou
Alpha Software Mobile Development Tools: Alpha Anywhere | Alpha TransForm |
FUNCTION Median as N (vcTableName as C, vcField as C, vcIndex as C) 'Calculates median value for specified table, field and index '� R A Rutherford 2008 'Declare & initialise variables OPTION strict DIM vnErr as N 'Error number for error handling routines DIM vcErrMsg as C 'Error message for error handling routines DIM vnResp as N 'User response to message box DIM t as P 'Pointer to selected table DIM vnRecCount as N 'Number of records DIM vnRecPos1 as N 'Position of 1st median record in index order DIM vnRecPos2 as N 'Position of 2nd median record in index order DIM vlSingleRecord as L 'Odd number of records? (therefore don't need to average values for two records) DIM vnValue1 as N 'Value of 1st median record in index order DIM vnValue2 as N 'Value of 2nd median record in index order DIM i as N 'Counter 'Open tables ON ERROR goto OpenError t = table.open(a5.Get_Path() + chr(92) + vcTableName + ".dbf", FILE_RO_SHARED) ON ERROR goto GeneralError t.index_primary_put(vcIndex) 'Get number of records vnRecCount = t.records_get() vnRecPos1 = vnRecCount / 2 IF vnRecPos1 <> int(vnRecPos1) THEN 'Odd number of records, so only need to look at one record vlSingleRecord = .T. vnRecPos1 = round_up(vnRecPos1, 0) ELSE vlSingleRecord = .F. vnRecPos1 = int(vnRecPos1) vnRecPos2 = vnRecPos1 + 1 END IF 'Fetch through records t.fetch_first() FOR i = 1 to vnRecPos1 - 1 t.fetch_next() NEXT vnValue1 = eval("t." + vcField) IF vlSingleRecord = .F. THEN t.fetch_next() vnValue2 = eval("t." + vcField) Median = (vnValue1 + vnValue2) / 2 ELSE Median = vnValue1 END IF 'Close table CloseAll: IF is_object(t) THEN t.close() END IF EXIT FUNCTION '*********************************************************** '//Error handling routines 'Errors not otherwise specified GeneralError: vnErr = error_code_get() vcErrMsg = error_text_get(vnErr) msgbox("Error", vcErrMsg, UI_STOP_SYMBOL + UI_OK) Median = 0 'possibly change this to an unlikely value e.g. -999999999? GOTO CloseAll 'Error opening table OpenError: vnResp = msgbox("Error opening table", "Cannot open the table for median calculation." + crlf() + "Another user may be using it.", UI_STOP_SYMBOL + UI_RETRY_CANCEL) IF vnResp = ui_retry_selected THEN RESUME 0 ELSE Median = 0 GOTO CloseAll END IF END FUNCTION
Comment