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

how to find a indexed fields on the table with code

Status
Not open for further replies.

kosta

Programmer
Feb 9, 2001
186
CA
Hi All,
i am designing for Database&DBF file maintenance form and using getfile(),adir() for this ( i am thinking globally for use every applicaion). dbf's selection button code like below

<pre>
* cdir,lcselected is public variable on form init
cdir=getdir()

CREATE CURSOR dosyalar (dosyaadi c(30),boyut c(10),degtar c(10),degzaman c(10),nicelik c(3))
lcselected=&quot;&quot;

gnDbcnumber = ADIR(gaDatabase, '&cdir.'+'*.DBF') && Create array

CLEAR
FOR nCount = 1 TO gnDbcnumber && Loop for number of databases
SELECT dosyalar
* ? gaDatabase(nCount,1) && Display database names
lcdosya=gaDatabase(nCount,1)
lcboyut=gaDatabase(nCount,2)
lcdtar=gaDatabase(nCount,3)
lcdzaman=gaDatabase(nCount,4)
lcnicelik=gaDatabase(nCount,5)
INSERT INTO dosyalar(dosyaadi,boyut,degtar,degzaman,nicelik) ;
values(TRANSFORM(lcdosya),TRANSFORM(lcboyut),TRANSFORM(lcdtar),TRANSFORM(lcdzaman),TRANSFORM(lcnicelik))
ENDFOR
GO top
thisform.grid1.RecordSource =&quot;dosyalar&quot;
thisform.grid1.SetFocus
thisform.grid1.refresh
lcselected= cdir + dosyalar.dosyaadi

thisform.Refresh
thisform.cmdtamamdbf.Enabled =.t.

</pre>

<pre>
USE &lcselected EXCLUSIVE
PACK
MESSAGEBOX(allt(&quot;&lcselected&quot;)+&quot; File has been maintenanced&quot;,64,&quot;maintenace report&quot;)

</pre>

my question : when the user select some file i can open and pack its like above code but how can find indexed fields and reindex its in a loop ? TIA



Soykan OEZCELIK
 
Here is some code I wrote a long time ago that opens a table. I like it because it checks for the existance of the index and saves code.

Rather than
IF USED('myTable')
SELECT myTable
SET ORDER TO myIndex
ELSE
SELECT 0
USE myTable
SET ORDER TO myIndex
ENDIF

* or something like that. You can use:

SELECTTABLE(&quot;myTable,&quot;myIndex&quot;)

* again, this code checks to see if the index exists and provides a nicer error if it does not.

You can easily modify this code to perform a PACK or REINDEX.

PROCEDURE SELECTTABLE
PARAMETER lc_tbl, lc_idx
* called to ensure a table is already open and the proper order is set
* if the table is not opened, it is opened.
* if the table is open - we ensure it is active and the order is
* checked to ensure it is correct
* if no order is passed, we will not do anything with the order

* Note: some of the macros may be able to be removed later.
* additional test for performance should be done when time permits.

IF !USED('&lc_tbl')
SELECT 0
USE &lc_tbl
ELSE
SELECT &lc_tbl
ENDIF

ll_foundit = .F.

IF PCOUNT() = 2
IF UPPER(ALLTRIM(ORDER())) <> UPPER(ALLTRIM('&lc_idx'))
FOR ln_Count = 1 TO 254 && vfp max # of tags is 254
lc_tagname = TAG(ln_Count)
IF !EMPTY(m.lc_tagname) && Chks for tags in the index
IF UPPER(ALLTRIM(m.lc_tagname)) == UPPER(ALLTRIM(m.lc_idx))
* We found the tag
m.ll_foundit = .T.
EXIT
ENDIF
ELSE
EXIT && Exit the loop when no more tags are found
ENDIF
ENDFOR

IF m.ll_foundit
SET ORDER TO TAG &lc_idx
ELSE
Inform(&quot;WARNING!!!&quot; + CRLF2 + ;
&quot;Tag: &quot; + m.lc_idx + &quot; was not found on table: &quot; + m.lc_tbl)
ENDIF
ENDIF
ENDIF


Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top