Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Repeating code in IF ELSE ENDIF
Message
 
 
À
13/01/2009 17:06:57
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01373379
Message ID:
01373386
Vues:
17
IF EMPTY(ALIAS()) OR FCOUNT() <> 2
	RELEASE lnTotalCodes
	SELECT (THIS.CurrentAlias)
	GOTO THIS.CurrentRecNo
	RETURN .F.

ELSE
	LOCAL ;
		lcTable, ;
		lcFields, ;
		lcOrderField
	lcFields = ''
	lnColumnCount = FCOUNT()
	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
ENDIF
>In the code below, I need to have the same block of code executed for both ELSE conditions. I never know how this should be done.
>Putting the block twice irritates my sense of oneness with the code, but I can't figure out how to handle it differently.
>
>IF !EMPTY(ALIAS())
>	LOCAL ;
>		lcTable, ;
>		lcFields, ;
>		lcOrderField
>	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
>		RELEASE lnTotalCodes
>		SELECT (THIS.CurrentAlias)
>		GOTO THIS.CurrentRecNo
>		RETURN .F.
>	ENDIF
>ELSE
>	RELEASE lnTotalCodes
>	SELECT (THIS.CurrentAlias)
>	GOTO THIS.CurrentRecNo
>	RETURN .F.
>ENDIF
>
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform