End (Statement)
Control flow statement to end the program.
Syntax
`
Declare Sub End ( ByVal retval As Integer = 0 )
`
Usage
`
End [ retval ]
`
Parameters
`retval`
Error code returned to system.
Description
Used to terminate the program, and return to the operating system. An optional integer return value can be specified to indicate an error code to the system. If no return value is given, a value of 0 is automatically returned.
Usage of this statement does not cleanly close scope. Variables and memory are not destroyed automatically and object destructors are not called. Calling the required destructors and other clean-up should be explicitly performed before an `End` statement.
Example
`
'' This program stores input from the user in a string, checks the strings length,
'' by calling valid_string, and either displays the string, or an error message
Function valid_string( s As String ) As Integer
Return Len( s )
End Function
'' assign input to text string (a string of spaces will input as an empty string)
Dim As String text
Print "Type in some text ( try ""abc"" ): " ;
Input text
'' check if string is valid (not empty). If so, print an error message and return
'' to the OS with error code -1
If( Not valid_string( text ) ) Then
Print "ERROR: you must enter a valid string"
Sleep : End -1
End If
'' string is valid, so print the string and return to the OS with error code 0
Print "You entered: " ; text
Sleep : End 0
`
Differences from QB

- The END statement supports specifying a custom return value to be returned to the operating system.

See also

- `End (Block)`