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!

Searching a Database?

Status
Not open for further replies.

Serincino

Programmer
Jun 13, 2003
61
US
In my app I have a search routine and form that I built. This form grabs all the database field names and populates a list box for the user to select which field they would like to search in. Unfortunately doing this requires that I have all fields indexed (creating a large index file). What I would really like to do is just index the fields that make sense to search on (not all fields make sense to search them like taxable a logical field), and then have the combo box populated with those field names. The easiest way I can see to do this is to just grab the index tag names, but it evades me on how I can just grab tag names on each database to populate the listbox. Can some one help me?
 
The Tag() function will list your index names. You can loop through and create either an array or table of tag names.
 
Serincino,

Here is some code that will accomplish something very similar to what jmcd0719 is suggesting Caution: I am assuming here that you do not have a table named Indexes.dbf in your datafolder...if you do then rename the Indexes.dbf in the code below to something unique. (Cut-n-paste the code below into a prg file and run it from within VFP, when prompted for a folder go locate your data folder)

LOCAL nlength, nCount
SET DEFAULT TO GETDIR()
=ADIR(aryTables,'*.DBF')
nlength = ALEN(aryTables)
nCount = 0
IF nlength > 0
IF FILE("indexes.dbf")
USE ("indexes.dbf") IN 0 EXCLUSIVE
ELSE
CREATE TABLE Indexes (table c(20), tag c(20), key c(100), cdx c(20))
ENDIF
SELECT INDEXES
ZAP
FOR i = 1 TO nlength STEP 5
IF UPPER(ALLTRIM(aryTables(i))) == "INDEXES.DBF"
LOOP
ENDIF
SELECT INDEXES
LOCATE FOR UPPER(ALLTRIM(INDEXES.TABLE)) == UPPER(ALLTRIM(JUSTSTEM(aryTables(i))))
IF FOUND("indexes")
DELETE FOR UPPER(ALLTRIM(INDEXES.TABLE)) == UPPER(ALLTRIM(JUSTSTEM(aryTables(i))))
ENDIF
USE (aryTables(i)) IN 0 EXCLUSIVE
SELECT (JUSTSTEM(aryTables(i)))
m.table = UPPER(ALLTRIM(ALIAS()))
m.cdx = UPPER(ALLTRIM(JUSTSTEM(CDX(1))))
FOR nCount = 1 TO 254
IF !EMPTY(ALLTRIM(TAG(nCount))) && Checks for tags in the index
m.tag = UPPER(ALLTRIM(TAG(nCount))) && Display tag name
m.key = UPPER(ALLTRIM(KEY(nCount))) && Display index expression
INSERT INTO INDEXES FROM MEMVAR
ELSE
EXIT && Exit the loop when no more tags are found
ENDIF
ENDFOR
USE IN (aryTables(i))
ENDFOR
SELECT INDEXES
PACK
Browse
ELSE
MESSAGEBOX("No Tables present in this directory!",16, "NOT A DATA DIRECTORY!")
ENDIF


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top