Set Format 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

Affects how MapBasic processes Strings that represent dates or numbers. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax 1

Set Format Date { "US" | "Local" } 

Syntax 2

Set Format Number { "9,999.9" | "Local" } 

Description

Users can configure various date and number formatting options by using control panels that are provided with the operating system. For example, a Windows user can change system date formatting by using the control panel provided with Windows.

Some MapBasic functions, such as the Str$() function, are affected by these system settings. In other words, some functions are unpredictable, because they produce different results under different system configurations.

The Set Format statement lets you force MapBasic to ignore the user's formatting options, so that functions such as the Str$() function behave in a predictable manner.

Statement Effect on your MapBasic application
Set Format Date "US"
MapBasic uses Month/Day/Year date formatting regardless of how the user's computer is set up.
Set Format Date "Local"
MapBasic uses whatever date-formatting options are configured on the user's computer.
Set Format Number "9,999.9"
The Format$() function uses U.S. number formatting options (decimal separator is a period; thousands separator is a comma), regardless of how the user's computer is configured.
Set Format Number "Local"
The Format$() function uses the number formatting options set up on the user's computer.

Syntax 1 (Set Format Date) affects the output produced under the following circumstances: Calling the StringToDate() function; passing a date to the Str$() function; or performing an operation that causes MapBasic to perform automatic conversion between dates and strings (for example, issuing a Print statement to print a date, or assigning a date value to a string variable).

Syntax 2 (Set Format Number) affects the output produced by the Format$() function and the FormatNumber$() function. Applications compiled with MapBasic 3.0 or earlier default to U.S. formatting. Applications compiled with MapBasic 4.0 or later default to "Local" formatting. To determine the formatting options currently in effect, call the SystemInfo() function. Each MapBasic application can issue Set Format statements without interfering with other applications.

Example

Suppose a date variable (date_var) contains the date June 11, 1995. The function call:

Str$( date_var )

may return "06/11/95" or "95/11/06" depending on the date formatting options set up on the user's computer. If you use the Set Format Date "US" statement before calling the Str$() function, you force the Str$() function to follow U.S. formatting (M/D/YY), which makes the results predictable.

See Also:

Format$() function, FormatNumber$() function, Str$() function, StringToDate() function, SystemInfo() function