Define 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

Defines a custom keyword with a constant value.

Restrictions

You cannot issue a Define statement through the MapBasic window.

Syntax

Define identifier definition

identifier is an identifier up to 31 characters long, beginning with a letter or underscore (_).

definition is the text MapBasic should substitute for each occurrence of identifier.

Description

The Define statement defines a new identifier. For the remainder of the program, whenever MapBasic encounters the same identifier the original definition will be substituted for the identifier. For examples of Define statements, see the standard MapBasic definitions file, MAPBASIC.DEF.

An identifier defined through a Define statement is not case-sensitive. If you use a Define statement to define the keyword FOO, your program can refer to the identifier as Foo or foo. You cannot use the Define statement to re-define a MapBasic keyword, such as Set or Create. For a list of reserved keywords, see Dim statement.

Examples

Your application may need to reference the mathematical value known as Pi, which has a value of approximately 3.141593. Accordingly, you might want to use the following definition:

Define PI 3.141593

Following such a definition, you could simply type PI wherever you needed to reference the value 3.141593.

The definition portion of a Define statement can include quotes. For example, the following statement creates a keyword with a definition including quotes:

Define FILE_NAME "World.tab"

The following Define is part of the standard definitions file, MAPBASIC.DEF. This Define provides an easy way of clearing the Message window:

Define CLS Print Chr$(12)