Displaying Information with Locale-Aware Functions and Statements

As explained previously, different locales have different conventions for displaying dates, times, numbers, currency, and other information. As a programmer, you cannot know the conventions for all your users' locales, and you don't have to know them. Many Visual Basic statements use the locale settings to determine the conventions automatically at run time, but some statements are more locale-aware than others. In general, Help tells you whether a statement or function is locale-aware, and if so, in what ways.

For example, the Print statement provides little flexibility for different output formats; it does, however, use the operating system locale settings. Dates are printed using the correct short date format, numbers are printed with the correct decimal separator, and currencies are printed with the correct symbol.

The Format function can accept format codes, but format codes always produce the same type of output without regard to the user's locale. For example, the format code "mm-dd-yy" isn't appropriate for locales in which the day precedes the month.

For more flexibility, the Format function also provides named formats that are locale-aware, including Short Date, Long Date, Long Time, and General Number. Using named formats produces output that's based on the user's operating system locale settings.


MyDate = #January 27, 1994#
MyStr = Format(MyDate, "dd-mm-yy")        'Returns 01-27-94
MyStr = Format(MyDate, "Short Date")        'Returns a short date based on
                                        'the locale where the code is                                             'running