Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to improve this code
Message
De
06/12/2006 21:40:40
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
06/12/2006 21:25:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 6
Divers
Thread ID:
01175464
Message ID:
01175466
Vues:
8
>
>sele csrtable
>go top
>do while .not. eof()
>	rch = csrkey
>	sele employee
>	go top
>	locate for rch=ckey
>	if found()
>		lc = locfle
>		sele csrtable
>		replace locfle with lc
>	enddo
>	skip
>enddo
>
For a start, you could use a SCAN, which saves several commands:
sele csrtable
scan
	rch = csrkey
	sele employee
	go top
	locate for rch=ckey
	if found()
		lc = locfle
		sele csrtable
		replace locfle with lc
	enddo
enddo
Next, you should use full commands (select instead of sele), and give your variables meaningful commands. Also, use variable naming conventions, and make sure your variables are declared. I'll omit renaming the variables for now.

You can omit "go top", since "locate" will start at the top.

In the locate command, I think, it is better to invert (if I understand correctly, ckey is the field, rch the variable), so that Rushmore Optimization works better.
select csrtable
scan
	rch = csrkey
	select employee
	locate for ckey = rch
	if found()
		lc = locfle
		select csrtable
		replace locfle with lc
	enddo
enddo
In your original code, you forgot to unconditionally go back to alias csrtable. (With SCAN, this is implicit.)
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform