Microsoft KB Archive/199244

= How To Retrieve the Regional Settings Currency Symbol =

Article ID: 199244

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q199244



SUMMARY
32-bit Visual Basic applications that are distributed in more than one country must rely upon the Regional Settings specifications of the Windows Control Panel for retrieving the appropriate currency symbol to display to the user. Retrieving the currency symbol involves calling the GetLocaleInfo function from the 32-bit Windows API function library.



MORE INFORMATION
The following code can be used to retrieve the currency symbol as specified in the Regional Settings of the Windows Control Panel. The GetUserDefaultLCID function retrieves the default locale for the current user and the GetLocaleInfo function retrieves information relating to the specified locale. Keep in mind that Visual Basic 6.0 has built in functions to automatically format numbers with the currency symbol as specified in the Control Panel's Regional Settings. While this code works in Visual Basic 6.0, the primary audience for this article are 32-bit Visual Basic 4.0 and Visual Basic 5.0 developers.

Executing this code stores the user default currency symbol in the Symbol string:

Option Explicit Private Declare Function GetLocaleInfo Lib "kernel32" _ Alias "GetLocaleInfoA" (ByVal Locale As Long, _     ByVal LCType As Long, ByVal lpLCData As String, _      ByVal cchData As Long) As Long Private Declare Function GetUserDefaultLCID% Lib "kernel32" Private Const LOCALE_SCURRENCY = &H14

Dim Symbol As String Dim iRet1 As Long Dim iRet2 As Long Dim lpLCDataVar As String Dim Pos As Integer Dim Locale as Long Locale = GetUserDefaultLCID iRet1 = GetLocaleInfo(Locale, LOCALE_SCURRENCY, lpLCDataVar, 0) Symbol = String$(iRet1, 0) iRet2 = GetLocaleInfo(Locale, LOCALE_SCURRENCY, Symbol, iRet1) Pos = InStr(Symbol, Chr$(0)) If Pos > 0 Then Symbol = Left$(Symbol, Pos - 1) End If

