Instruction Exit

Quitte une instruction Do...Loop, For...Next, une fonction, une propriété, un sous-programme.

Syntaxe :


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

Paramètres :

Exit Do

Applicable uniquement à l'intérieur d'une instruction Do...Loop ; permet de quitter la boucle. L'exécution du programme se poursuit par l'instruction figurant juste après l'instruction Loop. Si des instructions Do...Loop sont imbriquées, le contrôle est transféré à la boucle du prochain niveau supérieur.

Exit For

Applicable uniquement à l'intérieur d'une boucle For...Next ; permet de quitter cette boucle. L'exécution du programme se poursuit par la première instruction figurant après l'instruction Next. Dans des instructions imbriquées, le contrôle est transféré à la boucle du prochain niveau supérieur.

Exit Function

Quitte immédiatement la procédure Function. L'exécution du programme se poursuit par l'instruction figurant après l'appel de Function.

Exit Property

Quitte la procédure Property immédiatement. L'exécution du programme se poursuit avec l'instruction qui suit l'appel de l'instructionProperty.

Exit Sub

Quitte immédiatement la sous-routine. L'exécution du programme se poursuit par l'instruction figurant après l'appel de Sub.

IcĂ´ne Remarque

L'instruction Exit ne définit pas la fin d'une structure et ne doit pas être confondue avec l'instruction End.


Exemple :


Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
    For siStep = 0 To 10 ' Remplir la matrice avec les données de test
        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
' LinSearch recherche une TextArray:sList() pour une TextEntry :
' Renvoie l'index de l'entrée ou 0 (Null)
    For iCount=1 To Ubound( sList() )
        If sList( iCount ) = sItem Then
            Exit For ' sItem trouvé
        End If
    Next iCount
    If iCount = Ubound( sList() ) Then iCount = 0
    LinSearch = iCount
End Function

Aidez-nous !