|
Prev: Using MaskEdBox with Percent format
Next: Sounds
From: WonderMan on 3 Apr 2008 09:46 Hello, I'd like to be able to find out if the PC where my application is running has got French settings, US settings or any other international settings. My concern is to know which character is used (with the current settings) as the decimal point. In France, we use : 3,56 % In USA, they use : 3.56 % As a matter of fact, I use the FormatPercent() function in VB, and with french settings, I get a "type mismatch error" when trying : Dim mystring as String mystring = FormatPercent(CDec("12.45")/100,2) and everything works fine when trying : Dim mystring as String mystring = FormatPercent(CDec("12,45")/100,2) But I think things will be inversed if I tried to make this code run on a PC with US settings. Is there a possibility to manage this point, and make my program run with any country settings ? Thank you.
From: Wilko on 3 Apr 2008 10:33 WonderMan wrote: > Hello, > > > I'd like to be able to find out if the PC where my application is > running has got French settings, US settings or any other international > settings. > > My concern is to know which character is used (with the current > settings) as the decimal point. > > In France, we use : 3,56 % > In USA, they use : 3.56 % > > As a matter of fact, I use the FormatPercent() function in VB, and with > french settings, I get a "type mismatch error" when trying : > > Dim mystring as String > mystring = FormatPercent(CDec("12.45")/100,2) > > and everything works fine when trying : > > Dim mystring as String > mystring = FormatPercent(CDec("12,45")/100,2) > > But I think things will be inversed if I tried to make this code run on > a PC with US settings. > > Is there a possibility to manage this point, and make my program run > with any country settings ? > > Thank you. > > You can try code like this: DecPointChar$ = GetDecPointChar where GetDecPointChar is a function: Public Function GetDecPointChar$() Const LOCALE_SDECIMAL = &HE ' decimal separator Dim cchData As Long Dim LCType As Long Dim Locale As Long Dim lpLCData$ Dim Tmp As Long Locale = GetUserDefaultLCID LCType = LOCALE_SDECIMAL lpLCData = Space$(50) cchData = Len(lpLCData) Tmp = GetLocaleInfo(Locale, LCType, lpLCData, cchData) GetDecPointChar$ = Left$(lpLCData, InStr(lpLCData, Chr$(0)) - 1) End Function and the following declares are necessary Declare Function GetUserDefaultLCID Lib "kernel32" () As Long 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 That allows you to determine which is the current character for deceimal separator. To use the VAL function, you need to check the decimal separator because VAL(5,3) creates an error. I format a value into a string, replace the comma by a point, then use VAL. Not very straightforward but it works. Bye, Wilko
From: WonderMan on 3 Apr 2008 10:50 Il se trouve que Wilko a formul� : > WonderMan wrote: >> Hello, >> >> >> I'd like to be able to find out if the PC where my application is running >> has got French settings, US settings or any other international settings. >> >> My concern is to know which character is used (with the current settings) >> as the decimal point. >> >> In France, we use : 3,56 % >> In USA, they use : 3.56 % >> >> As a matter of fact, I use the FormatPercent() function in VB, and with >> french settings, I get a "type mismatch error" when trying : >> >> Dim mystring as String >> mystring = FormatPercent(CDec("12.45")/100,2) >> >> and everything works fine when trying : >> >> Dim mystring as String >> mystring = FormatPercent(CDec("12,45")/100,2) >> >> But I think things will be inversed if I tried to make this code run on a >> PC with US settings. >> >> Is there a possibility to manage this point, and make my program run with >> any country settings ? >> >> Thank you. >> >> > > Bye, > Wilko Thank you very much for taking the time to answer, and for giving me this excellent VB code.
From: Mike Williams on 3 Apr 2008 10:58 On 3 Apr, 14:46, WonderMan <n...(a)none.com> wrote: > My concern is to know which character > is used (with the current settings) > as the decimal point. This will do it for you: dec = Format(0, ".") Mike
From: Bert van den Dongen on 3 Apr 2008 11:30
I use a global variable "European". Public European as Boolean European = (mid(Format(12 / 10), 2, 1) = ",") Bert. >> My concern is to know which character >> is used (with the current settings) >> as the decimal point. |