Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic reference not working on For Each loop..
Message
From
08/04/2011 11:39:28
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Dynamic reference not working on For Each loop..
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01506642
Message ID:
01506642
Views:
127
Any idea why VFP doesn’t like this attempt to eval a local string var into an object reference:
Lparameters tcField, tcValue

Local lcContainer

lcContainer = 'Thisform.Container1.container' + tcField + '.Controls'

For each loControl in &lcContainer
	If Upper(control.baseclass) = 'CHECKBOX' and Upper(tcValue) $ Upper(loControl.caption)
		loControl.value = 0
		loControl.enabled = .f.
	EndIf
EndFor
It gives a "Nesting Error" messagebox *AT THE END* of the first pass through the loop. I can see in the debugger that “control” has been resolved as the first item in the collection of Controls and that it has made it to the EndFor line when the error message appears.

Why does it choke out with this syntax?


If I wrap in in parentheses it works fine:
For each control in (lcContainer)
  ...
EndFor
What's the difference here in () vs. &


.
Next
Reply
Map
View

Click here to load this message in the networking platform