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

SET INDEX TO ? 2

Status
Not open for further replies.

fbizzell

Programmer
Jul 3, 2000
217
I am working on a generic database editor where the user will put in a dbf file name and rather than having the user enter all the indexes I want to be able to extract the list of indexes from a table and build the SET INDEX TO string so I don't have to hard code it in the program and the user does not have to know the index names. I have seen this done somewhere but can't remember where.

 
Put the index filenames in a textfile, you could read it with the dbf name as a 'key'. I even found somewhere (dunno) a function to read/write ini files, so even some 'ignorent user' could update the file if needed...
HTH
TonHu
ps, I'll try to find the site with the ini functions later
 
i have some functions to write/read ini files... let me know and i can email them to you


bobby
 
I am not sure how the ini files are going to help me provide the indexes to open but here is my email address:

frank@bizzell.net

Thanks

 
As ini files are 'generic' configuration files, anyone using a computer before will understand that there must be some kind of configuration information inside.
You are now able to create an ini file with presumably a content like this:
Code:
filename: indexes.ini
(content of indexes.ini)
[mydbf1]
index1=dbf1ntx1
index2=dbf1ntx2

[data2]
index1=data2ntx1
index2=data2ntx2
index3=data2ntx3
index4=data2ntx4
(end of content)

The names of the data and index files are simple to make my point more clear (I hope).
So, inside de square brackets you'll find the databasenames without extension, as sections, and the indexes can be read starting from 1, incrementing until the result is empty. (Ini functions should return an empty string if not found). Then you have your 'dynamic' indexlist.

This is a sort of very simplified way of a 'datadictionary', that really doesn't deserve that name!

HTH,
TonHu
 
I am beginning to understand but how does a clipper application read the ini file to retrieve the indexes for a specific data file...let's say the user is wanting to browse and edit mydbf1 can the application pull the indexes just from that section?
 
As you are reading each line in the INI file, just check for the blank line separating the different sections. You could also check to see if the line starts with a '['. That would also indicate a new section has started.
 
I am not reading it yet at all. I am still back where I was trying to find the indexes to open for a specific data file. I have never used Clipper to read ini files to extract needed information from.

 
Elkari,

The blank line I just put in to make it readable...
A new section starts with a [ on pos. 1 of a new line, so that's the trigger to look for.

I found a nice function at Rolf van Gelder's clipper oriented site
You would look for 'rprofile' or 'ini to find it.

HTH
TonHu
 
You better have a database having the name of the databases and its related index file names and the index keys and conditions if any.

By using a small program u can select the index file names to a string and use SET INDEX TO &cstring

I have used this, and if u want i can send u the coding.

Durai.
 
I work with several Clipper apps that use a dbf to maintain the other dbf and index names, index expressions, etc.

It's used to verify that the index(s) are present, and if not, create them; open a dbf and all its indexes, without having to list each in the source code.

Same approach could be used in your requirement... if dbf name is passed as arguement at runtime, look it up in this dbf (or maybe an array that contains contents of your ini) and it would know which indexes to open with that dbf.
 
The last two posts were very helpful. I would like to have the coding mentioned by sduraiappan. My email address is fbizzell@atcomail.com

 
The ways circes9 describes is a full DD (datadictionary) system, like I built 12 years ago, and is enhanced up to a full screen designer, and banded report generator... ;-)
That's not the Q asked at first, and I didn't get the impression that this was needed, so I suggested the Q&E way, use 'textfiles' to go ahead.
If you are designing some new application, even around existing clipper databases, I would rather suggest taking a whole different route, as DOS development will be killed of by M$ within a few years. Just have a look at the (lack of) performance and even support of DOS apps under W2K or XP.

But that's a whole different discussion, and it has been held here before...

HTH, just keeping it simple s-)
TonHu
 
Here is my coding and the DBF i used is INDEACC.DBF

STRUCTURE:
DATABASE C 11
INDEXFLD C 40
INDEXFILE C 11
FORCOND C 40

PROCEDURE NDXER
PRIVATE NSTART,NEND,NTIME
STORE 0 TO RANGE,I
NSTART=SECONDS()
SELE A
USE INDEACC SHARED
GO TOP
MEN = 5
@11,45,21,72 BOX SPACE(9)
@11,45 TO 21,72 DOUBLE
@11,((45+72)-LEN('RE-INDEXING'))/2 SAY "RE-INDEXING" COLOR 'B+'
FILECTR = 1
MBAR_LENGTH = 22
COUNT TO MTOT_REC
MPERC = ROUND(MBAR_LENGTH/MTOT_REC,0)
MNUM = 100/MTOT_REC
@12,46 SAY "TOTAL FILES :" COLOR 'R+'
@13,46 SAY "FILES INDEXED :" COLOR 'R+'
@14,46 SAY "DATABASE FILE :" COLOR 'R+'
@15,46 SAY "INDEX FILE :" COLOR 'R+'
@16,46 SAY 'RECORD NUMBER :' COLOR 'R+'
@18,46 TO 20,71
@19,48 SAY REPL(CHR(219),MBAR_LENGTH) COLOR 'B'
GO TOP
DO WHILE !EOF()
MSHO = RECNO()
MDATABASE = A->DATABASE
MINDEXFLD = A->INDEXFLD
MINDEXFILE = A->INDEXFILE
MFOR = ALLTRIM(A->FORCOND)
@12,63 SAY LTRIM(STR(MTOT_REC,8)) COLOR 'GR+'
@13,63 SAY LTRIM(STR(FILECTR,8)) COLOR 'GR+'
@14,63 SAY MDATABASE COLOR 'GR+'
@15,63 SAY MINDEXFILE COLOR 'GR+'
@17,55 SAY SUBSTR(STR((FILECTR/MTOT_REC)*100),7,4)+" % COMPLETE" COLOR 'G+'
RANGE = MBAR_LENGTH*(FILECTR/MTOT_REC)
I = 0
DO WHILE I <= RANGE .AND. I <= MBAR_LENGTH
@19,48+I SAY CHR(219) COLOR &quot;R+&quot;
I = I+1
ENDDO
SELE B
USE &MDATABASE
IF LEN(ALLTRIM(MFOR)) > 0
INDE ON &MINDEXFLD TO &MINDEXFILE FOR &MFOR WHILE NUFUNC()
ELSE
INDE ON &MINDEXFLD TO &MINDEXFILE WHILE NUFUNC()
ENDIF
SELE A
IF !EOF()
SKIP
ELSE
EXIT
ENDIF
FILECTR = FILECTR + 1
ENDDO
SELE B
USE
SELE A
USE
NEND=SECONDS()
NTIME=NEND-NSTART
ALERT(ALLTRIM(STR(NTIME,10,0))+' Seconds Taken')
REST SCREEN
RETURN

FUNCTION TIMESTR(FSECONDS)
LOCAL KHOUR,KMINUTE,KSECONDS
FSECONDS=ROUND(VAL(FSECONDS),0)
IF FSECONDS>60
KMINUTE=INT(FSECONDS/60)
KSECONDS=INT(FSECONDS%60)
ELSE
KSECONDS = FSECONDS
KMINUTE=0
ENDIF
IF KMINUTE>60
KHOUR = INT(KMINUTE/60)
KMINUTE=INT(KMINUTE%60)
ELSE
KHOUR=0
ENDIF
TSTG = PADL(ALLTRIM(STR(KHOUR)),2,'0')+':'
TSTG = TSTG+PADL(ALLTRIM(STR(KMINUTE)),2,'0')+':'
TSTG = TSTG+PADL(ALLTRIM(STR(KSECONDS)),2,'0')
RETURN TSTG

FUNCTION NUFUNC()
IF EOF()
RFLAG = .F.
ELSE
@16,62 SAY ALLTRIM(STR(RECNO())) COLOR 'GR+'
@16,COL() SAY '/' COLOR 'R+'
@16,COL() SAY ALLTRIM(STR(LASTREC())) COLOR 'R+'
RFLAG = .T.
NEND=SECONDS()
NTIME=ALLTRIM(STR(NEND-NSTART,10,2))
@20,52 SAY &quot;TIME:&quot;+TIMESTR(NTIME) COLOR &quot;BG+&quot;
ENDIF
RETURN RFLAG


I hope u need no comments on this Program

Durai.
 
I Think I have not given the coding for what you really want.

Here I have shown you the coding, which I use for Packing the Databases with
its index files.

PROCEDURE PACKDBF()
SELE A
USE INDEACC SHARED
INDEX ON DATABASE TO (TEMPNTX)
DO WHILE !EOF()
SELE A
TDB = A->DATABASE
TNTX = ''
DO WHILE TDB = A->DATABASE .AND. !EOF()
TNTX = TNTX + ALLTRIM(A->INDEXFILE)+'.NTX'
SKIP
IF TDB = DATABASE
TNTX = TNTX + ', '
ENDIF
ENDDO
* MESG('Packing...'+TDB+'-'+TNTX)
SELE B
USE (TDB) INDEX (TNTX)
PACK
USE
SELE A
ENDDO
SELE A
USE
RETURN

I hope you dont need any comments on the coding.


S.Duraiappan.
 
What I was looking for was a way to automatically enter the index names whenever I am wanting to browse and edit a data file that has several indexes. If I could store the index file names in a text file that I could read and select from and open the indexes along with the dbf file.
 
Seasons Greetings to all.

I use STRUCTURE EXTENDED type databases for maintaining
and updating the integrity of all my packages...
In a database called WCMASTER I list all field definitions of every supported database...

DATABASE SEQNO FIELDNAME FIELDTYPE FIELD_SIZE FIELD_DEC
control 001 username C 30
control 002 lic_users N 3 0
stock 001 prodcode C 15
stock 002 descript C 35
stock 003 date_on D 8
stock 004 costprice N 10 2
stock 004 prodgroup C 2

Whenever I want the users to update any field changes I
simply send them just the field definitions of those databases that have changed....

If I want the package to always re-establish the integrity
of all databases I simply save the file WCMASTER.DBF as
WCMASTER.SAV and tell the package to copy WCMASTER.SAV
to WCMASTER.DBF when they perform a full index rebuild or
integrity check...

Then, my packages have code in the LOG-IN area that will
detect the presence of the incoming database WCMASTER.DBF
and if the CONTROL.DBF can be FLOCK()ed the user is the
SOLE USER (package can safely USE WCMASTER.DBF EXCLUSIVE)
... creates an index on DATABASE + SEQNO + FIELDNAME
... extracts the definitions for each database to TEMP.DBF
... APPENDs the data from the existing database
... ERASEs the source database
... ERASEs the source .DBT file (if detected)
... RENAMEs the TEMP.DBF to the original database name
... RENAMEs the TEMP.DBT (if detected)

Next, I also maintain a database with INDEX KEY definitions
DATABASE INDEXNAME SETORDER SEQNO KEYFIELD
stock prodcode 1 1 prodcode
stock prodname 2 1 UPPER(descript)
stock prodgrp 3 1 prodgroup
stock prodgrp 3 2 prodcode

My packages contain code that detects the presence of
WCINDEXK and for each indexname creates index files using
a concatenation of the KEYFIELDS
eg INDEX ON prodcode TO prodcode
INDEX ON UPPER(descript) TO prodname
INDEX ON prodgroup+prodcode TO prodgrp
Using the ORDER field the package then knows that when/if
opening the database 'stock' that the setorder is:-
SET INDEX TO prodcode,prodname,prodgrp

Next, my Report/Label generator modules create/alter/replay script files that have extension .XEQ
They are simple ASCii text files containing 20 lines each
of 64 characters...
#DESCRIBE--> REPORT TO PRINT PRICE LISTS IN GROUP ORDER
#DATAFILES-> stock
-->
#INDEXES --> prodgrp
-->
#LOOKUPKEY-> prodgroup,prodcode
-->
#ALIASNAME->
-->
#SORTING -->
#FORMAT --> PRICELST.frm
#HEADING -->
#CRITERIA--> NONSTOCK <> 'Y' .AND. .NOT. DELETED()


...

#END

Hope this is the sort of help you are looking for,
If not, email me at <jwild@xtra.co.nz> or post another
reply here... I will keep watch...
Cheers,
Jim Wild (t/a Wildcard Systems)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top