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

Iterating through table names with # values at the end. 1

Status
Not open for further replies.

DSaba10

Programmer
Joined
Nov 15, 2007
Messages
35
Location
US
Hello All,

Using VFP 6.0, trying to iterate through some .dbf field names that have #'s at the end (ex: field1, field2). Is there any way to do this without having to list out each field individually?

My Code currently looks like this:

Code:
mlybi = 1
	DO WHILE mlybi <= 10
		IF (('gdate' + alltrim(str(mlybi))) < mLybMAX) and (('gdate' + alltrim(str(mlybi))) > mLybMIN)
			mLybCnt = mLybCnt + 1
		ENDIF
		mlybi = mlybi + 1
	ENDDO

Right now, I do realize that it's just comparing the string equivalent of 'gdate#' rather than field name gdate# against another string (mLybMAX, mLybMIN). Is there a way to append a number at the end of a field name? I have 20 gdate# fields to process through and I'd rather not have to list them out if at all possible.

Thanks!
 
Is this what you had in mind?
Code:
FOR i = 1 TO 10
	cFldName = 'gdate'+ALLTRIM(STR(i))
	IF &cFldName. < mLybMAX and &cFldName. > mLybMIN
		mLybCnt = mLybCnt + 1
	ENDIF
NEXT i
or if you don't like macros:
Code:
FOR i = 1 TO 10
	cFldName = 'gdate'+ALLTRIM(STR(i))
	IF EVALUATE(cFldName) < mLybMAX and EVALUATE(cFldName) > mLybMIN
		mLybCnt = mLybCnt + 1
	ENDIF
NEXT i

Mike Krausnick
Dublin, California
 
Ooo. That is perfect. If you couldn't tell from my code snippet, I'm a used to coding in C languages. That makes my day. Thank you much!

-Doug
 
You're welcome, and thanks for the star.

Mike Krausnick
Dublin, California
 
ok so I have an addition to my question!

I'm trying to swap some things around from different dbf's and here is the code I came up with:

Code:
set talk off
close all
clear

SELECT 1 
	use dpmpstru order interid
SELECT 2 
	use K:\DBDATA\Idaho08\00StruProg\idaho_desig order desigcde
	
	
SELECT 1

DO WHILE .NOT. EOF()
	
	FOR i = 1 to 10
		
		mGdetCde = 'gdet' + ALLTRIM(STR(i))
		
		if &mGdetCde <> ' '
			store &mGdetCde to mDetCde
		else
			LOOP
		endif
			
		SELECT 2
			find &mDetCde
			
			if FOUND()
				store desigdesc to mDesigCde
			ENDIF
		SELECT 1
		
		replace &GdetCde with mDesigCde
	NEXT i
	
	SELECT 1
	
	SKIP
ENDDO

It dies right at the point of "replace &GdetCde with mDesigCde" and I've not been able to find a combination to make this work. Does this look like a good way to do this, or am I going about it wrong?

Thanks!

-Doug
 
Ok well I finally managed to figure it out myself.

Code:
set talk off
close all
clear

SELECT 1 
	use dpmpstru order interid
SELECT 2 
	use K:\DBDATA\Idaho08\00StruProg\idaho_desig order desigcde
	
	
SELECT 1

DO WHILE .NOT. EOF()
	
	FOR i = 1 to 10
		
		mGdetCde = 'gdet' + ALLTRIM(STR(i))
		
		if &mGdetCde <> ' '
			store trim(&mGdetCde) to mDetCde
		else
			LOOP
		endif
			
		SELECT 2
			find &mDetCde
			
			if FOUND()
				store desigdesc to mDesigCde
			else 
				store 'Unknown' to mDesigCde
			ENDIF
		SELECT 1
		
		replace &mGdetCde with mDesigCde
	NEXT i
	
	SELECT 1
	
	SKIP
ENDDO

Perhaps my blunder will one day help another!

-Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top