Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random records
Message
De
26/12/2004 19:30:34
 
 
À
26/12/2004 07:12:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Divers
Thread ID:
00972179
Message ID:
00972237
Vues:
11
>hi all,
>i want to insert to mynewtable total of records randomly
>as
>thisform.text1.value=778
>my code under copy this records but not randomly
>any idea.
>
>USE moh11
>COPY TO newmoh111 NEXT  (thisform.text1.value)
>
>thanks.
>m.qasem

Do you want to take 778 randomly selected records from MOH11 and insert them into NEWMOH111?

If so, you might take a look at the following. It is probably not the fastest way of getting the job done, but it might work for you.
PROCEDURE rand_insert
LPARAMETERS tcSource,tcTarget,tnNumRecs
** tcSource = Alias of Source records
** tcTarget = Name of Target file
** tnNumRecs = Number of random records to copy

lnHighVal = RECCOUNT(tcSource)
DIME aRandRecs[tnNumRecs]

lnInsert = 0
DO WHILE lnInsert < tnNumRecs
    lnRandNum = IRAND(1,lnHighVal)
    IF ASCAN(aRandRecs,lnRandNum) = 0
        lnInsert = lnInsert + 1
        aRandRecs[lnInsert] = lnRandNum
    ENDIF
ENDDO

lnCurWa = SELECT()
SELECT (tcSource)
COPY TO (tcTarget) FOR ASCAN(aRandRecs,RECNO()) <> 0
SELECT (lnCurWa)
and place the following code in the command button (I assume) which actually does the work
DO thisform.rand_insert WITH "moh11","newmoh111",thisform.text1.value
FUNCTION irand
PARAMETER i, j
** This is from the help files. You will need to create a separate method for it or put
** it in your procedure file somewhere
RETURN int((j-i+1)*rand( )+i)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform