Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I put multiple commands on a single line?
Message
De
17/09/1999 00:20:35
 
 
À
15/09/1999 10:40:40
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00264921
Message ID:
00265750
Vues:
21
Hi Sylvain. I disagree with your point as I can use function to do so:

For below Procedure, I can do For-loop, While-loop, Scan..EndScan by One Line Command!

For instance,

=FL(1,6,"? ix, Chr(64+ix)")

Will print:

1 A
2 B
3 C
4 D
5 E
6 F

If you modify the FL procedure by cuting down the cAction with Chr(13),
You can handle more than ONE line command in For-loop!!

but In the First Time I post this proc at UT, ppl said I can highlight the coding and
right-click and select "Execute the highlight region" to do..
That's means no need to make those proc!


**	FOR LOOP
PROCEDURE FL	&& make one line simple For-Loop
LPARAMETERS nStart, nEnd, cAction, cExit, cLoop

DO CASE
CASE PCOUNT() = 3
	FOR ix = nStart TO nEnd
		&cAction
	ENDFOR

CASE PCOUNT() = 4
	FOR ix = nStart TO nEnd
		&cAction
		IF (&cExit)
			EXIT
		ENDIF
	ENDFOR

CASE PCOUNT() = 5
	IF !EMPTY(cExit)
		FOR ix = nStart TO nEnd
			&cAction
			IF (&cExit)
				EXIT
			ENDIF
			IF (&cLoop)
				LOOP
			ENDIF
		ENDFOR
	ELSE
		FOR ix = nStart TO nEnd
			&cAction
			IF (&cLoop)
				LOOP
			ENDIF
		ENDFOR
	ENDIF
ENDCASE
ENDPROC

** WHILE LOOP
PROCEDURE WL	&& make one line simple While-Loop
LPARAMETERS cCondition, cAction, cExit, cLoop

DO CASE
CASE PCOUNT() = 2
	DO WHILE &cCondition
		&cAction
	ENDDO

CASE PCOUNT() = 3
	DO WHILE &cCondition
		&cAction
		IF (&cExit)
			EXIT
		ENDIF
	ENDDO

CASE PCOUNT() = 4
	IF !EMPTY(cExit)
		DO WHILE &cCondition
			&cAction
			IF (&cExit)
				EXIT
			ENDIF
		ENDDO
	ELSE
		DO WHILE &cCondition
			&cAction
			IF (&cExit)
				EXIT
			ENDIF
			IF (&cLoop)
				LOOP
			ENDIF
		ENDDO
	ENDIF
	
ENDCASE
ENDPROC

** SCAN FOR
PROCEDURE SF	&& make one line SCAN.. ENDSCAN
LPARAMETERS cFor, cAction, cExit

DO CASE
CASE PCOUNT() = 2
	SCAN FOR &cFor
		&cAction
	ENDSCAN

CASE PCOUNT() = 3
	SCAN FOR &cFor
		&cAction
		IF (&cExit)
			EXIT
		ENDIF
	ENDSCAN

ENDCASE
ENDPROC

**	SCAN WHILE
PROCEDURE SW	&& make one line SCAN.. ENDSCAN
LPARAMETERS cWhile, cAction, cExit

DO CASE
CASE PCOUNT() = 2
	SCAN WHILE &cWhile
		&cAction
	ENDSCAN

CASE PCOUNT() = 3
	SCAN WHILE &cWhile
		&cAction
		IF (&cExit)
			EXIT
		ENDIF
	ENDSCAN

ENDCASE
ENDPROC


>You can't place more than one command on one line in VFP.
>
>Is a FOR loop like this would help?
>
>
FOR lnI = 1 TO FCount()
>   laMyArray[lnI] = Field(lnI)
>ENDFOR

>I have the following code:
>>LOCAL laMyArray(4)
>>laMyArray(1) = "MyTable.MyField 1"
>>laMyArray(2) = "MyTable.MyField 2"
>>laMyArray(3) = "MyTable.MyField 3"
>>laMyArray(4) = "MyTable.MyField 4"
>>
>>But I would like to do the following code:
>>LOCAL laMyArray(4)
>>laMyArray(1) = "MyTable.MyField 1" laMyArray(2) = "MyTable.MyField 2"
>>laMyArray(3) = "MyTable.MyField 3" laMyArray(4) = "MyTable.MyField 4"
>>
>>The reason I want to do this is because I have as many as 21 elements in my array and it would be easier to read multiple commands grouped as above rather than scrolling down 21 lines. I would only have to scroll down 11 lines. Will this syntax work or what character is needed to separate the commands?
>>
>>I thought I read this somewhere, but I don't remember the answer.
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform