Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Repeating code in IF ELSE ENDIF
Message
 
To
13/01/2009 17:06:57
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01373379
Message ID:
01373383
Views:
25
In those cases I tend to use a logical variable
IF !EMPTY(ALIAS())
	LOCAL ;
		lcTable, ;
		lcFields, ;
		lcOrderField, ;
		llEarlyExit && or whatever, starts with .f.

	lcFields = ''
	lcTable = ALLTRIM(UPPER(JUSTSTEM(ALIAS())))
	lnColumnCount = FCOUNT(lcTable)
	IF lnColumnCount = 2
		FOR ix = 1 TO lnColumnCount
			lcFields = m.lcFields + IIF(m.ix > 1, ', ','') + FIELD(ix) + ' AS Fld'+TRANSFORM(ix)
			IF m.ix = 1
				lcOrderField = FIELD(ix)
			ENDIF
		ENDFOR
		RunSQL = 'SELECT ' + lcFields + ' FROM ' + lcTable + ' ORDER BY ' + lcOrderField + ' INTO CURSOR ReportCursor HAVING !EMPTY(Fld1)'
		&RunSQL
		lnTotalCodes = _TALLY
	ELSE
		llEarlyExit = .t.
	ENDIF
ELSE
	llEarlyExit = .t.
ENDIF

IF llEarlyExit
	RELEASE lnTotalCodes
	SELECT (THIS.CurrentAlias)
	GOTO THIS.CurrentRecNo
ENDIF
RETURN NOT llEarlyExit
Now, that said, in this case the code you are repeating is mostly unnecessary or required anyways, you do not need RELEASE lnTotalCodes (it should be a local variable) and you do not need to restore the record number, as the SQL will open the table again with different alias, and you need to restore the current alias and return the flag value anyways

[Update] I just noticed that the local declaration was inside the first if, for the llEarlyExit variable it should be outside, sorry
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform