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

index on question on vfp6 and vfp9 1

Status
Not open for further replies.
Aug 22, 2019
8
TW
i use the same code as below
sele 1
set exclu off
use outa
copy stru to tx3
sele 9
USE tx3
index on dtoc(date)+out_no tag tx3
in vfp6 will not have problem,
but in my vfp9 will have error
file must be opened exclusive
why,
and other people's vfp9 also no error
 
How about a completely different approach:

To create a new temporary table, with the same structure as an existing table, and then to index the temporary table:

Code:
SELECT * FROM ExistingTable WHERE .F. INTO CURSOR TempTable READWRITE
SELECT TempTable
INDEX ON TheField TAG TheTag

Henry, does do what you want?

If so, and if you are now faced with amending 1,000 programs, I can only repeat what we have suggested: write a program to do it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I imagine this rather being about creating tables per customer or per month, a system you wouldn't need to make that complicated for any reason. For the reason of file size limits? Perhaps in the long run, but not per month. And storing data per customer or client or tenant is also just one aspect of data privacy.

Anyway, if there are 1000s of places something like that is done, a function doing so, of course, doesn't resolve the need to place 1000 calls of the new function. So the burden of this task is much more of an overall deal with never upgrading the VFP version for 20 years and not regularly enhancing and refactoring code making use of new features. Edit: I assume such a system is worked on all the time, I don't assume it is kept as is just because 1999 we already had VFP7 2001, development simply continued with VFP6. But that alone means not profiting of newer features.

There's a term for it: Technical debt. That's more about bad code design, independent on the version of a programming language used, but updates of the language of course play into it, as new language versions give new features leading to shorter easier to maintain code. But at some point, your technical debt either becomes much work that could have been a relaxed side task in the past or even the end of your business.

Assumption: The structural copies of tables vary so much in how they are to be indexed, that he didn't bother writing a function. But COPY STRU WITH CDX or COPY TO WITH CDX actually copy all indexes you already once defined in the original table, so there is no need for individual code when that is the only goal. That means you don't even need individual INDEX ON and you can shrink down much code and replace it with a single line even not writing a function. I'd still do a function, as it would provide a way to centralize the organization of files in folders to just one PRG or even class. That means alone the concept to let a class be responsible for when, how and where tables are copied means you also will only need to change that in one place in the future. A big strategy change could be simply maintaining a directory of empty tables you simple copy per month, the only part of names that will change are then names of the target directory containing the year and month or directories with client names, then your code doesn't even need to copy table structures on the fly and just in time. While just in time solutions can be fine for some problems, if that leads to 1000 places in code you do something, that's not really a good design, is it?

No matter what the detail reasons are, the idea is not just to centralize a "macro" of 5-10 lines to a function, but to consider why you would need something like that scattered at 1000 places in code at all and if this can't be centralised and even done ar application start once per month, for example, for the whole database or folder of tables and not just a single table. A directory of empty indexed tables you only use to copy them for your client/trenent/time period use will be much easier to maintain and your code handling this data will just need to CD into the right directory to work on that data "partition".

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi,
I hate to jump in when two experts are giving already very wise advises.
Why do you create an index with your procedure?
Would it not be simpler to change your dbf and create an index in your table?
Then in you can just
Code:
 select myTable shared 
set index to myIndex
Now install Thor with GoFish and all your 1000 codes in your program you can find "index on dtoc(date)+out_no tag tx3' and replace with the simpler version.
One word: DONOT use the Replace function of Thor, repeat DO NOT. Replace all 1000's by hand.
Regards,
Koen
 
In VFP6 I use this sort of code, tailored for each application to find things:
Code:
PRIVATE m.FLG
SET TALK OFF
SET MEMOWIDTH TO 250
CLOSE ALL
M.PROJNAME = LEFT("EASYWORKS"+SPACE(50),50)
M.PROJDIR = LEFT("D:\DEV\EASYWORKS"+SPACE(50),50)
M.DATADIR = LEFT("c:\FLOWDATA"+SPACE(50),50)
M.DATANAME = LEFT("EASYWORKS"+SPACE(50),50)
M.LOOKFOR	= SPACE(50)
CLEAR
@ 10,10 SAY "Project Main File"
@ 10,30 GET m.PROJNAME PICTURE "@!"
@ 11,10 SAY "Project Directory"
@ 11,30 GET m.PROJDIR PICTURE "@!"
@ 12,10 SAY "Data Directory"
@ 12,30 GET m.DATADIR PICTURE "@!"
@ 13,10 SAY "Database Name"
@ 13,30 GET m.DATANAME PICTURE "@!"
@ 14,10 SAY "Look For"
@ 14,30 GET m.LOOKFOR PICTURE "@!"
READ
CLEAR GETS
@ 16,0 SAY ""
IF LASTKEY() <> 27
	CLOSE ALL
	USE (TRIM(m.PROJDIR)+"\"+TRIM(m.PROJNAME)+".PJX") ALIAS PROJNAME
	GO TOP
	SET ALTE TO D:\DEV\EASYWORKS\REPFILE.TXT
	SET ALTE ON
	DO WHILE .NOT. EOF()
		DO CASE
		CASE TYPE= "K"
			*@ 18,10 SAY PROJNAME.KEY
			SELECT 0
			IF FILE(TRIM(m.PROJDIR)+"\"+TRIM(PROJNAME.KEY)+".SCX")
				USE (TRIM(m.PROJDIR)+"\"+TRIM(PROJNAME.KEY)+".SCX") ALIAS FORMNAME
				DO WHILE .NOT. EOF()
					IF !EMPTY(FORMNAME.METHODS)
						NUMLINES = MEMLINES(FORMNAME.METHODS)
						M.STRING = ""
						M.FLG = .F.
						M.ALIAS = ""
						FOR I = 1 TO NUMLINES
							M.MEMOLINE = MLINE(FORMNAME.METHODS,I)
							IF TRIM(m.LOOKFOR)$UPPER(m.MEMOLINE)
								M.FLG = .T.
								? PROJNAME.KEY ," : " , m.MEMOLINE
							ENDIF
						NEXT
					ENDIF
					SKIP
				ENDDO
				SELECT FORMNAME
				USE
			ENDIF
		ENDCASE
		SELECT PROJNAME
		SKIP
	ENDDO
	SET ALTE OFF
	SET ALTE TO
	SELECT PROJNAME
	USE
ENDIF

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top