Comment récupérer le symbole décimal et le séparateur des milliers défini par l'utilisateur dans le panneau de configuration ?
La solution la plus simple consiste à employer astucieusement la fonction
"Format" comme ceci :
Dim SymboleDecimal As String
Dim SeparateurMillier As String
SymboleDecimal = Format(0, ".")
SeparateurMillier = Format(0, " ")
La deuxième solution, plus compliquée, consiste à employer l'API
GetLocaleInfo. L'avantage de cette API est qu'elle vous permettra de récupérer
aussi d'autres paramètres régionaux.
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 GetSystemDefaultLCID Lib "kernel32" () As
Long
Private Const LOCALE_SDECIMAL = &HE ' Symbole décimal
Private Const LOCALE_STHOUSAND = &HF ' Séparateur des milliers
Private Sub Form_Load()
Dim SymboleDecimal As String
Dim SeparateurMillier As String
Dim sBuffer As String
Dim nBufferLen As Long
Dim LCID As Long
LCID = GetSystemDefaultLCID
nBufferLen = 255
sBuffer = String$(nBufferLen, vbNullChar)
nBufferLen = GetLocaleInfo(LCID, LOCALE_SDECIMAL, sBuffer,
nBufferLen)
If nBufferLen > 0 Then
SymboleDecimal = Left$(sBuffer,
nBufferLen - 1)
MsgBox "Le symbole décimal est
: " & SymboleDecimal, vbInformation
Else
MsgBox "Erreur",
vbExclamation
End If
nBufferLen = 255
sBuffer = String$(nBufferLen, vbNullChar)
nBufferLen = GetLocaleInfo(LCID, LOCALE_STHOUSAND, sBuffer,
nBufferLen)
If nBufferLen > 0 Then
SeparateurMillier = Left$(sBuffer,
nBufferLen - 1)
MsgBox "Le séparateur des
milliers est : " & SeparateurMillier, vbInformation
Else
MsgBox "Erreur",
vbExclamation
End If
End Sub Voir aussi : |
Date de publication : 14 juillet 2002
Dernière modification : 14 juillet 2002
Rubriques : Math
Mots-clés : décimal, symbole, séparateur, milliers, panneau de configuration, virgule, point, nombre |