Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with the function
Message
 
 
À
25/10/2000 12:59:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00434138
Message ID:
00434175
Vues:
24
Hi Daniel,

I implemented your idea. My original function didn't work correctly. When you set order to something, then goto recodrNumber, it goes to the record in original sequence (recno()), not the record in current order. So I can not use goto command in order to get median value. Your solution works fine. It also cut off the size of the program:
***************************************************************************
*  Description.......: GetMedianValue - returns median value from a specified table
*  Calling Samples...: GetMedianValue('curPrice','LstSlPrice')
*  Parameter List....: pcTableName, pcField
*  Created by........: Daniel Rouleau  #025397
*  Modified by.......: Nadya Nosonovsky 10/25/2000 11:43:05 AM
*****************************************************************************
* Returns median value or .f. for unsuccessful cases
lparameters pcTableName, pcField
local lnMiddleRecord
* pcTableName - name of the table or already opened cursor, which should be processed
* pcFiled     - name of the field, which used in calculation, price, for example
* Both parameters are optional, if they are not specified, current working alias is used and price field
lnOldSelect=select() && Save current area
llCloseDBF=.f.
if empty(pcField) or vartype(pcField)<>'C'
     pcField=upper('price')
else
     pcField=upper(pcField)
endif
if empty(pcTableName) or vartype(pcTableName)<>'C'
     pcTableName=alias() && Current open alias
     if empty(pcTableName) && No current table
          return .f.
     endif
endif
release aResult
select &pcField from (pcTableName) into array aResult order by 1
if _tally>3
  lnMiddleRecord=ceiling(_tally/2)
else
       =messagebox('Number of records is less than 3. Can not calculate median...',48)
       return .f.
endif  
return aResult[lnMiddleRecord]
>Nadya:
>
>You can use something like
>
>SELECT (tcField) FROM (tcTable) INTO ARRAY MyArray
>=ASORT(MyArray)
>RETURN ( MyArray[CEILING(ALEN(MyArray)/2)) )
>
>if you don't want to create/use an index tag.
>
>The error handler needs to handle your special cases.
>
>Daniel
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform