REM {Assign ListOne to ListResult using an @For loop.
Use concatenation on all but the first iteration.};
@For(n := 1; n <= @Elements(ListOne); n := n + 1;
FIELD ListResult := @If(
n = 1;
ListOne[n];
ListResult : (ListOne[n])
)
)
この短いコードには、多くの新しい関数が含まれています。
一時的な変数である n は繰り返し割り当てられています!以前の Rnext では一時的変数を
@Set でしか繰り返し割り当てることができなかったので、変数を利用する操作は式の中ではできませんでした。
REM {This code adds 2 lists using a loop.};
@For(n := 1; n <= @Elements(ListOne); n := n + 1;
FIELD ListResult := @If(
n = 1;
ListOne[n] + ListTwo[n];
ListResult : (ListOne[n] + ListTwo[n])
)
)
次のループは、要素を1つのリスト(ListOne の @Sum)にまとめます。
REM {This statement sums the elements in one list using a loop.};
FIELD Result := 0;
@For(n :=1; n <= @Elements(ListOne); n := n + 1;
FIELD Result := Result + ListOne[n]
)
REM {We cannot do this with a list operation because each add
uses the result of the previous add.};
@For(n := 1; n <= @Elements(ListOne); n := n + 1;
FIELD ListResult := @If(
n = 1;
ListOne[n] + ListTwo[n];
ListResult : (ListResult[n-1] + ListOne[n] + ListTwo[n])
)
)
REM {We cannot do this with one operation because the @Prompt statements
must be serial. This loop collects string items one item at a time by prompting
the user and adds them to a list. };
item := @Prompt([OKCANCELEDIT]; "Item"; "Enter item or \"
\""; "");
@While(
item != "";
FIELD ListResult := @If(
ListResult = "";
item;
ListResult : item
);
item := @Prompt([OKCANCELEDIT]; "Item"; "Enter item
or \" \" to quit"; "")
)
REM {This is a condensed version of the @While loop. };
@While(
(item := @Prompt([OKCANCELEDIT]; "Item"; "Enter item
or \" \""; "")) != "";
FIELD ListResult := @If(
ListResult = "";
item;
ListResult : item
)
)
REM {An @DoWhile loop processes the loop body
before checking the condition.};
@If(ListOne = ""; @Return(0); "");
n := 0;
@DoWhile(
n := n + 1;
@Prompt([OK]; "Element " + @Text(n); ListOne[n]);
((n < @Elements(ListOne)) & (ListOne[n] != "END*OF*LIST"))
)
@For(n := 1; n <= @Elements(custName); n := n+1;
FIELD result := @If(n = 1;@If(@Compare(custName[n];"d"; [CaseInsensitive])
= -1;custName[n];"");@If(@Compare(custName[n];"d";
[CaseInsensitive]) = -1;result:(custName[n]);result)));
result
しかしながら、参照に失敗し名前が返されない場合は "The second argument
to @Subset must not be zero" というエラーが表示されます。このエラーを未然に防ぐためには上の式の
@Elements を @Count に変更します。するとこの関数は、引き出されたリストの1番目のエントリーを返します。
@IfError(@If(@Sign(dif)=-1;@Max(anthony_yrtotal;result);
@Max(result;maria_yrtotal));"One of your list fields is empty");
意味が分かり難いエラー・メッセージを表示する代わりに、@IfError 関数は目的のフィールドに
"One of your list fields is empty" というテキストを表示させます。これにより、ユーザーにデータの入力を促すのです。
2つ目のエラー、"The second argument to @Subset must not be zero"
を防ぐためには、tantony と tmaria 割り当てステートメント内の @Elements
関数を @Count に置き換えます。@Count は、評価中のフィールドが null である場合に、0ではなく1を返すのです。