【问题标题】:shortcut of multi-conditions with and in AL and Business Central?使用 AL 和 Business Central 的多条件快捷方式?
【发布时间】:2022-08-12 19:36:24
【问题描述】:

假设我们有程序is_even如果给定的数字是偶数,则返回!
这是一个很好的代码:

if is_even(22) = true or test(1) = true  or test(2)  = true then
    //...

甚至那更好:

if true in [ is_even(22), is_even(1), is_even(2) ] then
    //..

但是如果我这样做但有逻辑怎么办(and不是or) 像那样

if is_even(22) = true and test(1) = true  and test(2)  = true then
    //...

更好的代码会是什么?

我尝试过这样做,所以我想用python all 中的函数来做到这一点:

local procedure all(array_bools : ARRAY [3] OF Boolean): Boolean
var
    bool: Boolean;
    i: Integer;
begin
    REPEAT
        bool := array_bools[i];
        if bool = false then 
            exit(false);
        i := i + 1;
    UNTIL i <> ARRAYLEN(array_bools);
    exit(false);
end;

它没有像我预期的那样工作

if all([is_even(22), is_even(1), is_even(2)]) = true then
  • 这似乎过于复杂。为什么不只是if not array_bools[i] then exit(false);?同样&lt;&gt; ARRAYLEN(array_bools) 从一开始就注定了。你想要&gt; ARRAYLEN(array_bools),因为当i = 0(数组的开始)它自动&lt;&gt; ARRAYLEN(array_bools)

标签: microsoft-dynamics dynamics-al businesscentral msdyn365bc


【解决方案1】:

这辆车的最佳选择在这里: 如果 iseven(22) 或 test(1) 或 test(2) 那么

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 1970-01-01
    • 2023-02-19
    • 2022-11-04
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    相关资源
    最近更新 更多