Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Array in VFP

Status
Not open for further replies.

VBFOXDEV35

Programmer
Mar 26, 2001
77
US
All:

Hey another question. Has anyone written, found, etc a control array in VFP that works just like a VB control array?

My problem is I have this form with any textbox controls. each textbox is named exactly as a field in a database (no the controls are not bound). I want to know if there is a way to create a control array that I can loop through and write the data to the database where

Control name = field name
Thisform.(fieldname).text = fieldname

Any thoughts?

Art
Art DeGaetano II
Software Developer, MOUS
 
No control arrays in VFP, however with some "creative" macro expansion you can make this work. e.g.
Code:
xx = "fieldname"
Thisform.&xx..text = fieldname
Note: The first "." after a & is the terminator, the second in this case is the normal property selector.

Rick

 
So you are saying you can read the name from the database and then macro sub that field name to find the proper control?

That makes sense.

Art
Art DeGaetano II
Software Developer, MOUS
 
You can also use this structure:

FOR EACH loCtrl IN THISFORM.Controls
lcFldName = loCtrl.Name
REPLACE alias.&lcFldName with loCtrl.Value
ENDFOR


****************
Personally, I rather do this:

in Form.Load
USE table ALIAS tabalias
SCATTER NAME THISFORM.oRec

**
Then, bind each textbox to THISFORM.oRec.FieldName

and, when it's time to save the data,

GATHER NAME THISFORM.oRec
 
There is also the AFIELDS() function:

*... Get list of fields in selected table
nFieldCount = AFIELDS(aFieldList)
FOR i = 1 TO nFieldCount
STORE aFieldList[i, 1] TO cTmp
REPLACE alias.&cTmp WITH ThisForm.&cTmp..Text
NEXT

This is untested, but you get the idea.
Dave S.
 
Thanks to you all.

WGCS, tried your method last night and it kicked A$%&^

I knew there was a way with VFP!

Thanks

Art
Art DeGaetano II
Software Developer, MOUS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top