RSS Feed

VBScript tip: Changing the locale settings

November 12, 2014 | Bretislav Valek

A locale is a set of parameters that defines the language, country, and other specific options (e.g., alphabetical sorting and date, time, number, and currency formats). Some of the VBScript functions use the locale settings. It is, for example, the MonthName function, which returns a string indicating the specified month. The locale settings also affects the way the value of a tag is converted into a string, i.e., for example, the format in which the value of a DateTime tag (date and time) is displayed.


The locale's default value in Reliance scripts is English (United States). Therefore, the DateTime tag's value converted into a string will be displayed as follows:


Dim d, dow, wdn
d = Date
dow = WeekDay(d)
wdn = WeekDayName(dow)
MsgBox wdn & ", " & d, vbSystemModal

Default settings


If this is not satisfactory or the settings must be changed (e.g., based on the program or project language), you can use the SetLocale function, which expects the locale identifier as a parameter. The DateTime tag's value converted into a string will then be displayed as follows:


Dim d, dow, wdn
SetLocale "cs"
d = Date
dow = WeekDay(d)
wdn = WeekDayName(dow)
MsgBox wdn & ", " & d, vbSystemModal

Local settings


The GetLocale function is intended to return the current locale ID value.


Unfortunately, changing the locale settings using the SetLocale function does not affect the way the value of a Boolean-type tag is converted into a string. The result depends on the Windows language. For example, on the Czech version of Windows, the value of the Boolean-type tag is converted into the Czech equivalent of either "True" (Pravda) or "False" (Nepravda). The solution is to implement a function that always returns "True" or "False".


function BoolToStr(a)
  if a then
    BoolToStr = "True"
  else
    BoolToStr = "False"
  end if
end function

The function can then be called to convert the value.


Dim a, b
a = True
b = False
MsgBox BoolToStr(a) & " " & BoolToStr(b)

True, False


Reliance Earth Icon

Top