Breaking out of loop in form

Emilia
Member Posts: 4
Is there a way to "break" out of a loop in a form? The only way that seems to work is EXIT, but I do not want to EXIT because I still want to run the rest of the code for other cases. BREAK/SKIP/QUIT do not work either. They seem to only work on reports, i.e. CurrReport.BREAK;
What is the BREAK version for forms? Something that works like CurrReport.BREAK but in forms.
What is the BREAK version for forms? Something that works like CurrReport.BREAK but in forms.
0
Comments
-
Could you explain what you are trying to do?
You can use a Boolean value to control a loop in code.
Example
MyBool := FALSE;
REPEAT
Your Code Here
Set MyBool = TRUE when condition met.
UNTIL (NEXT = 0) OR MyBoolThere are no bugs - only undocumented features.0 -
Let's say I have this code:
IF PromoDet2.FINDSET THEN
REPEAT
CASE PromoDet2."Sales Type" OF
PromoDet2."Sales Type"::Item :
BEGIN
IF SalesLine2.INSERT THEN
CurrForm.CLOSE;
EXIT; // I want to replace this exit with someting similar to break
END;
PromoDet2."Sales Type"::"Product Group" :
BEGIN
//code here
END;
PromoDet2."Sales Type"::"Shipping Agent Service":
BEGIN
//code here
END;
END;
UNTIL PromoDet2.NEXT = 0;
Instead of using EXIT, I want to use something similar to BREAK, so that the rest of the code in other cases can still be run. This code is done on a form, so I cannot do things like CurrReport.BREAK.
My question is that how do you break out of that IF statement above without using EXIT?0 -
Savatage wrote:I think your thinking about this wrong.
I'm assuming you mean that if condition 1 is true you want it to go to the end like Pascal or something.
The condition can only be true once and you have to loop thru for each line (if I get you correctly). Do you think that the other code will run if condition 1 is true?
Where are you putting your code?
This is someting you might use on a OnValidate TriggerCASE Type OF Type::" ": BEGIN //Some Code END; Type::"Account (G/L)": BEGIN //Some Code END; Type::Item: BEGIN //Some Code END; Type::Resource: BEGIN //Some Code END; Type::"Fixed Asset": BEGIN //Some Code END; END;
PS Don't forget about your
If..Then..Else's or Then Begin..Else Begin..too
They can be very useful0 -
Emilia wrote:.....so that the rest of the code in other cases can still be run...0
-
I have a REPEAT... UNTIL surrounding these cases. Let's say that there are 3 things that fulfil the condition of my REPEAT... UNTIL loop. I want to break out of the IF statement so that the REPEAT... UNTIL loop (and the different cases within it) can be run again for the other things that also fulfil the condition of my REPEAT... UNTIL loop.0
-
I think the problem that is confusing is
1) not know what you are trying to do
2) looking at your code I just looked quick and saw you wanted to use case but how could a "shipping agent service" or "product group" be a sales type?
you might be just setting this up all wrong - that's why we need to know what you are trying to accomplish0 -
Consider this (and the suggestion had already been made):
ConditionOne := FALSE; IF PromoDet2.FINDSET THEN REPEAT CASE PromoDet2."Sales Type" OF PromoDet2."Sales Type"::Item : BEGIN IF SalesLine2.INSERT THEN BEGIN CurrForm.CLOSE; //EXIT; // I want to replace this exit with someting similar to break ConditionOne := TRUE; END; END; PromoDet2."Sales Type"::"Product Group" : BEGIN //code here END; PromoDet2."Sales Type"::"Shipping Agent Service": BEGIN //code here END; END; UNTIL (PromoDet2.NEXT = 0) OR (ConditionOne = TRUE);
The only issue is that it will still execute any code you'd have after the point where you want to exit.
So there is no keyword to exit a loop in C/AL, but you CAN make the loop stop if a condition is met, by including that condition in the UNTIL part.0 -
make sure you reset the value of the variable ConditionOne before using it.No future at CPI0
-
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions