LOTUSSCRIPT 言語
ユーザーが値を入力します。値が 1、2、3 のときは、On...GoTo ステートメントが label1、label2、または label3 に制御を移します。値が On...GoTo の範囲 (0 - 255) 内の別の数値のときは、制御は次のステートメントに移ります。On...GoTo の範囲外の数値、または Cint 関数で整数に変換できない値を入力すると、エラー条件が発生し、OnError...GoTo ステートメントが制御を OutOfRange ラベルに移します。
ユーザー入力に応じて、OneTwoThree サブルーチンが適切なメッセージを表示します。入力が有効なときは、Exit Sub ステートメントがサブルーチンを終了します。入力が無効なときは、制御が EnterNum ラベルに移るので、有効な値を入力し直せます。
Sub OneTwoThree Dim num As Integer On Error GoTo OutOfRange EnterNum: num% = CInt(InputBox("Enter 1, 2, or 3")) On num% GoTo label1, label2, label3 ' The user did not enter 1, 2, or 3, but a run-time error ' did not occur (the user entered a number in the ' range 0-255). MessageBox "You did not enter a correct value!Try again!" GoTo EnterNum label1: MessageBox "You entered 1." Exit Sub label2: MessageBox "You entered 2." Exit Sub label3: MessageBox "You entered 3." Exit Sub ' An error condition has occurred. OutOfRange: MessageBox "The value you entered is negative, " _ & "greater than 255, or is not a number.Try again!" GoTo EnterNum End Sub OneTwoThree ' Call the OneTwoThree sub.
関連項目