FANDOM


It's easy to write code in VFP that will generate VFP code. I had to do this a while back when writing a program to convert one data file into another format. Many of the field names were not compliant with Fox naming standards, and several of the fields were being used for purposes unrelated to their original names.

I decided that the easiest way to handle this would be to have Fox generate the CREATE TABLE command for me, so I wouldn't have to worry about maintenance as much. I told it to put comments at the end of each line so that I'd remember what old field name corresponded to the new one I was creating.

*!* lcRefStructure was actually the header line of a 
*!* tab-delimited file in the original app
lcRefStructure = "longFieldName1" + CHR(9) ;
	+ "longFieldName2" + CHR(9) ;
	+ "reallyLongFieldName3"

lnFldCount = ALINES(laStru, lcRefStructure, .T., CHR(9))

_cliptext = "CREATE TABLE NewDBF ( ; " + CHR(13) + CHR(10)
FOR i = 1 TO lnFldCount
	_cliptext = _cliptext + CHR(9) + " C()" ;
		+ IIF(i < lnFldCount, ",", "") + " ;" ;
		+ CHR(9) + "&" + "& " + laStru(i) + CHR(13) + CHR(10)
ENDFOR
_cliptext = _cliptext + ")"

This program puts the following output on the clipboard, ready to paste into your program and come up with new field names and lengths.

CREATE TABLE NewDBF ( ; 
	 C(), ;	&& longFieldName1
	 C(), ;	&& longFieldName2
	 C() ;	&& reallyLongFieldName3
)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.