Thursday, December 31, 2015

Find String In Tables using Visual Foxpro

This short program looks for a text string in all columns of all tables of a VFP database and returns table.field locations where found. Helpful for me to get rid of certain text from across the database tables. Author: Michael J. Babcock, MCP  Freeware 1.3K Last updated: 2009.02.06

* Program: Find_string_in_tables.prg
* Author: Michael J. Babcock, MCP
* Created: 01-30-2009
* Purpose: To detect a string value in any field in an open database.
* Comments: Feel free to improve and re-post to ProFox!

LOCAL liCnt as Integer, liLoop as Integer, laFields(1), laTables(1), lcText as String 
CLEAR 
lcText = "MBSS" && this is what you're searching for somewhere in your database tables
CLOSE TABLES ALL && I'm assuming the database to be open at this point, but closing any tables
liCnt = ADBOBJECTS(laTables,"TABLE") && you could adjust this so that you could look at free table directories too
WAIT WINDOW "Ready to search " + ALLTRIM(STR(liCnt)) + " tables...press any key"
FOR EACH cTable IN laTables
WAIT WINDOW NOWAIT "Searching " + cTable
USE (cTable) 
liCnt = AFIELDS(laFields,cTable)
FOR liLoop = 1 TO liCnt
IF laFields(liLoop,2) = "C" THEN && search for string
lcCmd = [LOCATE FOR '] + ALLTRIM(UPPER(lcText)) + [' $ UPPER(] + laFields(liLoop,1) + [)]
EXECSCRIPT(lcCmd)
IF FOUND() THEN 
? "Found match in table " + cTable + "." + laFields(liLoop,1)
*WAIT WINDOW "Found match in table " + cTable
EXIT && loop to next field
ENDIF 
ENDIF
ENDFOR 
USE IN (cTable)
ENDFOR 
WAIT WINDOW "Finished!"





No comments:

Post a Comment