Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sum numbers in a field
Message
De
28/03/2013 10:32:39
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01569439
Message ID:
01569445
Vues:
48
>e.g. "30, 32, 10, 1000," = 1072
m1 = "30, 32, 10, 1000"
m2 = CHRTRAN(m1,",","+")
? &m2
30+ 32+ 10+ 1000"
>Could you explain how "&" executes the sum ?
>I have used "&" to other things but didn't understand how it works.


It's called macro substitution. What it does is look at the contents of the string as a command, rather than as a string. Some other examples:
k = "thisForm.visible = .f."
&k
* This actually executed the command "thisForm.visible = .f." because that was what k contained
* If it's changed to something else, the same command "&k" executes something else

k = "thisForm.visible = .t."
&k

* In the case of your example, it's like doing this kind of math:
k = "foo = 30 + 20 + 18"
&k
* Right now, foo has been assigned to 68

* And in your explicit example:
k = "30+ 32+ 10+ 1000"
? &k
* It does the operation of the math as though you had typed "? 30+ 32+ 10+ 1000"
* The & tells VFP to do it as a command, rather than data.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform