xsharp.eu • EXIT in FOR Loop
Page 1 of 2

EXIT in FOR Loop

Posted: Mon Apr 22, 2024 10:08 am
by lagraf
Hallo,
warum bringt folgender Code einen Fehler
error XS9089: Functions cannot have an INIT or EXIT clause.

Code: Select all

METHOD [Name]
LOCAL x AS DWORD
FOR x := 1 to 9999
	IF [Bedingung]
		EXIT
	ENDIF
NEXT

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 10:33 am
by FFF
Da muss noch was anderes sein.

Code: Select all

FUNCTION Start( ) AS VOID
VAR t :=test{}
? t:z()

CLASS  test
METHOD z() AS DWORD
	LOCAL x AS DWORD
FOR x := 1 TO 9999
	IF TRUE
		EXIT
	ENDIF
NEXT
RETURN x
END CLASS
compiliert bei mir ohne Fehler oder Warnung.

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 10:59 am
by lagraf
Hallo Karl,
der Code liegt bei mir in einer Methode einer Klasse (und läuft in VO tadellos), interessanterweise bekomme ich aber noch einen anderen Fehler ein paar Zeilen davor, vielleicht hängen die beiden zusammen:
XS9002: Parser: unexpected input 'nPos'

Code: Select all

CLASS dlgLsBuchen INHERIT dlgLsBuchen_vo
PROTECT _cLiefnr AS STRING
PROTECT _aVor AS ARRAY
...
METHOD GetArtField(cCol AS STRING, lFormel := TRUE AS LOGIC)
LOCAL x AS DWORD
LOCAL odbAGR AS dbAgr
LOCAL nPos AS DWORD
...
nPos := AScan(_aVor, {|aVal|aVal[1] == Upper(cCol)})	// => XS9002
odbAgr := dbAgr{}
FOR x := 1 TO 9999
	odbAgr:Seek({#LIEFNR, #AGRNR}, {_cLiefnr, x}, FALSE)
	IF !odbAgr:Found  .OR. odbAgr:FIELDGET(#TXT) == "SONSTIGES"
		EXIT								// => XS9089
	ENDIF
NEXT
odbAgr:Close()
LG Franz

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 11:30 am
by robert
Franz,

LOPCAL should probably be LOCAL


Robert

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 11:32 am
by lagraf
Hi Robert,
that's only a typing error, in sourcecode it's correct!
Franz

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 12:08 pm
by robert
Franz,

The best way for us to help you to detect the error is if you include the complete source code.
With snippets of code, this is not possible.
For example: does your class end with END CLASS?


Robert

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 12:17 pm
by lagraf
Hi Robert,
Class ends with END CLASS.
Here's the class transported from VO to X#, if you need whole project, pls tell me.

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 2:41 pm
by Chris
Hi Franz,

It's because of the PRIVATE variables declared in the method body of GetArtField(), the parser does not expect them and loses sync. If you really need them, you need to enable support for them in the compiler options, in the App properties, Compiler page, check /memvar: Support MEMVAR, PRIVATE, PUBLIC vars.

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 4:50 pm
by lagraf
Hi Chris,
the privates are because of the Macrocompiler later in this Method, it compiles user defined formulas.
I changed properties to /memvar
Franz

Re: EXIT in FOR Loop

Posted: Mon Apr 22, 2024 8:57 pm
by Chris
Hi Franz,

OK, in that case, in order to avoid having this compiler option always enabled, it's probably better to have it enabled only locally, in this method that needs it. So you would add a

#pragma options ("memvar", on )

just before the method that uses them, and at the end of it a

#pragma options ("memvar", default )

But I see that the compiler has a problem with it, I think the compiler itself accepts it, but the parser is not aware of the pragma and still reports an error. Not sure if this is fixable, but will create a bug report for Robert to have a look.