End Program statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Halts a MapBasic application.

Restrictions

The End Program statement may not be issued from the MapBasic window.

Syntax

End Program

Description

The End Program statement halts execution of a MapBasic program. A MapBasic application can add items to MapInfo Pro menus, and even add entirely new menus to the menu bar. Typically, a menu item added in this fashion calls a sub procedure from a MapBasic program. Once a MapBasic application has connected a procedure to the menu in this fashion, the application is said to be "sleeping."

If any procedure in a MapBasic application issues an End Program statement, that entire application is halted―even if "sleeping" procedures have been attached to custom menu items. When an application halts, MapInfo Pro automatically removes any menu items created by that application.

If an application defines a procedure named EndHandler, MapBasic automatically calls that procedure when the application halts, for whatever reason the application halts.

Interpreted Mode

While executing a MapBasic script in the interpreted mode (which does not support conditionals like the "if" statement), you need a way to stop the script. To achieve this, you can now use the End Program statement in the interpreted mode:

End Program [Condition(expr)] ' The Condition clause is optional

expr is a boolean (logical) expression. If True, the execution of the script text is stopped. If False, the execution continues.

Note: This does not apply to compiled MapBasic.
print "before"
fetch first from usa
End Program Condition(usa.State="AL")
print "after"

If the first state is AL, then the print "after" statement will not be executed.

See Also:

End MapInfo statement, EndHandler procedure