Compartir a través de


SetLocale Function

 

Sets the global locale and returns the previous locale.

Syntax

SetLocale(lcid)

Remarks

The lcid argument can be any valid 32-bit value or short string that uniquely identifies a geographical locale. Recognized values can be found in the Locale ID chart.

If lcid is zero, the locale is set to match the current system setting.

A locale is a set of user preference information related to the user's language, country/region, and cultural conventions. The locale determines such things as keyboard layout, alphabetical sort order, and date, time, number, and currency formats.

The following example illustrates the use of the SetLocale function. To use this code, paste the whole example between into an HTML page.

<html>
<head>
    <title>Locale Converter</title>
</head>

<body>
    <table cellpadding="2">
        <tr>
            <td>Convert</td>
            <td>
               <input type="text" id="inputText" size="10" value="12/15/2009" />
            </td>
        </tr>

        <tr>
            <td></td>
            <td>
                <input type="radio" name="radioGroup" checked="checked" />Date
                <input type="radio" name="radioGroup" />Currency
            </td>
        </tr>

        <tr>
            <td>From Locale ID</td>
            <td>
               <input type="text" id="fromLocaleID" size="7" value="en-us" />
            </td>
        </tr>

        <tr>
            <td>To Locale ID</td>
            <td>
               <input type="text" id="toLocaleID" size="7" value="fr-fr" />
            </td>
        </tr>

        <tr>
            <td>
                <input type="button" value="Convert" id="convertButton" />
            </td>
            <td>
               <input type="text" readonly="readonly" id="outputText" size="10" />
            </td>
        </tr>
    </table>
    

    <script language="vbscript" type="text/vbscript">
    
    Option Explicit

    Sub convertButton_onclick
        Dim currentLocale, theDate, theCurr
        
        currentLocale = GetLocale
        
        if radioGroup(0).checked Then
            SetLocale(fromLocaleID.value)
            theDate = CDate(inputText.value)
            SetLocale(toLocaleID.value)
            outputText.value = FormatDateTime(theDate, vbShortDate)    
        Else
            SetLocale(fromLocaleID.value)
            theCurr = CCur(inputText.value)
            SetLocale(toLocaleID.value)
            outputText.value = FormatCurrency(theCurr)
        End If

        SetLocale (currentLocale)
    End Sub

    </script> 

</body>
</html>

Change History

Date

History

Reason

January 2010

Modified example.

Information enhancement.

See Also

GetLocale Function
Locale ID (LCID) Chart