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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get details of the tables collection 2

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
I am trying to find a collection that would hold details of all the FREE tables open. I have found references to an XML table collection and details of database containers but that is not what I am after.

My aim is to write some code that will loop through a table collection so I can get details of fields such as name, type, length etc.

Mark Davies
Warwickshire County Council
 
Check AFIELDS() in Help.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
mdav2,
Copy this code into something like structure.prg, and put it in the directory that has the tables in it. Start fox, set your default to that location, and type DO STRUCTURE.PRG.
It will prompt you for a file name, that will generate all the tables structes to a list. You can play with this code to do what you like, if you're after something else, but I think this is what you are looking for (or close to it... I may be giving too much "data collection" with this routine, but chop out what you don't want.)

Code:
SET TALK OFF
CLEAR
CLOSE DATA
*
M.PRNFILE = SPACE(50)
M.NEWPAGE = 'Y'
M.ANS = 'Q'
*
@ 1,2 SAY 'LIST INDEX KEYS AND STRUCTURE OF DATA TABLES'
@ 2,15 SAY 'IN CURRENT DIRECTORY'
@ 4,2 SAY 'Print File Name?' GET M.PRNFILE PICTURE '@!'
@ 5,2 SAY 'Leave blank to print to current default printer'
@ 6,2 SAY 'NEW PAGE for each table listing? (Y/N)' GET M.NEWPAGE PICTURE '@!'
@ 7,2 SAY '<P>roceed or <Q>uit?' GET M.ANS PICTURE '@!'
READ
*
IF M.ANS <> 'P'
	SET TALK ON
	RETURN
ENDIF
*
M.PRNFILE = ALLTRIM(M.PRNFILE)
IF NOT(EMPTY(M.PRNFILE))
	IF FILE(M.PRNFILE)
		M.ANS = 'N'
		? CHR(7)
		@ 8,2 SAY 'File already exists! Overwrite? (Y/N)' GET M.ANS PICTURE '@!'
		READ
		IF M.ANS <> 'Y'
			RETURN
		ENDIF
	ENDIF
ENDIF
*
SET PRINT ON
SET DEVICE TO PRINT
IF NOT EMPTY(M.PRNFILE)
	SET PRINTER TO (M.PRNFILE)
ENDIF
*
DIMENSION DBFSLIST[1]
= ADIR(DBFSLIST,'*.DBF')
= ASORT(DBFSLIST)
NUMFILES = ALEN(DBFSLIST,1)
*
FOR NDX = 1 TO NUMFILES
	FILENAME = ALLTRIM(DBFSLIST[NDX,1])
	USE (FILENAME)
	?
	? FILENAME
	?
	DO LISTTAGS
	?
	LIST STRU TO PRINT
	IF M.NEWPAGE = 'Y'
		EJECT
	ENDIF
ENDFOR
*
CLOSE DATA
*
EJECT
*
SET PRINT OFF
SET DEVICE TO SCREEN
SET PRINTER TO
SET TALK ON
*
RETURN
*
* * * * * * * * *
*
PROCEDURE LISTTAGS
*
PRIVATE NDX
*
FOR NDX = 1 TO 256
	IF EMPTY(TAG(NDX))
		EXIT
	ENDIF
	M.NDXKEY = KEY(NDX)
	M.NDXTAG = TAG(NDX)
	? 'INDEX ON ' + M.NDXKEY + ' TAG ' + M.NDXTAG
	SET ORDER TO TAG (M.NDXTAG)
	IF 'DESCENDING' $ UPPER(SET('ORDER'))
		?? ' DESCENDING'
	ENDIF
*
ENDFOR
*
IF EMPTY(TAG(1))
	? 'NO INDEX KEY/TAG FOUND'
ENDIF
*
M.CHKFPT = SUBSTR(FILENAME,1,RAT('.',FILENAME)-1) + '.FPT'
IF FILE(M.CHKFPT)
	?
	? 'MEMO FILE '+M.CHKFPT+' APPEARS TO BE PRESENT'
ENDIF
*


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Thanks for the posts I think the AFIELDS command will do the job I want.

Mark Davies
Warwickshire County Council
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top