Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Will the 'Fox is Dead' prophecies become self-fulfilling
Message
De
13/12/1999 14:03:35
 
 
À
13/12/1999 09:49:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00301589
Message ID:
00302864
Vues:
25
>>What is your objection to the code that you listed?
>>
>>>DO WHILE !EOF()
>>>REPLACE field1 WITH value1
>>>REPLACE field2 WITH value2
>>>REPLACE field3 WITH value3
>>>REPLACE field4 WITH value4
>>>REPLACE field5 WITH value5
>>>
>>>*....replace more fields
>>>
>>>SKIP
>>>
>>>LOOP
>>>
>>>ENDDO
>
>This code can be done in one line:
>
>REPLACE ALL Field1 with Value1,;
> Field2 with Value2,;
> Field3 with Value3,;
> Field4 with Value4,;
> Field5 with Value5
>
>And, it will run alot faster than above... OF COURSE... I think that this may also do a file lock... so, if you need to avoid that, the avbove way, while a bit less efficient will only lock records. So, there is really more GRAY here than black and white.
>
>BOb

Actually there is still another way
SCAN
REPLACE field1 WITH value1,;
field2 WITH value2,;
field3 WITH value3....

ENDSCAN

This is always faster than replacing one field at a time.

Weirdly enough this can be faster than REPLACE ALL in many cases -- especially if you are replacing a subset of the table. (That is REPLACE REST WHILE is often slower than using a loop.) The hackers guide documents this.

It is not consistent -- so if unless this is an area where performance is not critical, I tend to test on a case by case basis.
Thanks

Gar W. Lipow
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform