Exit Statement

Exits a Do...Loop, For...Next, a function, a property, or a subroutine.

Syntax:


Exit Do, Exit For, Exit Function, Exit Property, Exit Sub

Parameters:

Exit Do

Do...Loop ステートメント内部でのみ使用可能で、ループを強制的に終了させます。プログラムの処理は、終了したループステートメント以降のコードを続行します。Do...Loop ステートメントがネストされている場合、プログラムの処理は、より上位レベルのループに移されます。

Exit For

For...Next ステートメント内部でのみ使用可能で、ループを強制的に終了させます。プログラムの処理は、終了した Next ステートメント以降のコードを続行します。ステートメントがネストされている場合、プログラムの処理は、より上位レベルのループに移されます。

Exit Function

Function プロシージャーを強制的に終了させます。プログラムの処理は、該当する Function を呼び出したコードの次にあるステートメントから続行されます。

Exit Property

Exits the Property procedure immediately. Program execution continues with the statement that follows the Property call.

Exit Sub

サブルーチンを強制的に終了させます。プログラムの処理は、該当する Sub を呼び出したコードの次にあるステートメントから続行されます。

注マーク

この Exit ステートメントは、End ステートメントとは異なり、サブルーチンなどのブロックの終了部を宣言するものではないので注意が必要です。


Example:


Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
    For siStep = 0 to 10  REM 配列にテスト用データを代入
        sListArray(siStep) = chr(siStep + 65)
        MsgBox sListArray(siStep)
    Next siStep
    sReturn = LinSearch(sListArray(), "B")
    Print sReturn
End Sub
 
Function LinSearch( sList(), sItem As String ) As Integer
Dim iCount As Integer
REM LinSearch はテキスト配列:  sList() 内に指定文字列を検索:
REM 戻り値は、該当するインデックス値ないしゼロ (Null)
    For iCount=1 To Ubound( sList() )
        If sList( iCount ) = sItem Then
            Exit for REM 検索で sItem がヒット
        End If
    Next iCount
    If iCount = Ubound( sList() ) Then iCount = 0
    LinSearch = iCount
End Function

ご支援をお願いします!