Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A neat little 'gotcha' in VFP
Message
From
28/06/2006 14:25:04
 
 
To
28/06/2006 13:29:38
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgia, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01132511
Message ID:
01132524
Views:
14
From the help file...

If a variable has the same name as a field, Visual FoxPro always gives precedence to the field name. You can reference the variable using m. or m-> plus the variable name, as in the following examples.



>If you run the little code snippet below it will not give you the results you expect. However, in proc secprg if you change x and y to m.x and m.y, you will get the desire results. This VFP behavior just bit me in the *** big time when I added a field to a table in an application and was dismayed to be alerted by uses that a part of my program which had worked flawlessly for years suddenly was broken.
>
>Clear
>Create Table test Free (x n(1),y n(1))
>Use test
>Append blank
>Replace x With 3
>Replace y With 5
>?x
>?y
>Do secprg
>?x
>?y
>Use In test
>Delete File test.dbf
>
>****************
>Procedure secprg
>local x,y
>x='a'
>y='b'
>?x
>?y
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform