borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Receiving "Out of memory" error message) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Coma and dot separator for decimal numbers
Poster Message
iliekater
Level: Master

Registered: 04-02-2005
Posts: 125

icon Coma and dot separator for decimal numbers

I have run into a problem that has to do with the way that a computer separates decimal numbers from the integers . As you may know , on some languages  this separator is the coma "," while on others the dot "." . Some of the users of a program of mine complain that this creates problem for them since they have Windows set on the wrong language setting (my program is made to use dot separator) . I have told them that and some of them changed that option , thus no longer having problem . However , some of them canot do that becouse this will create problems on other programs they use . Therfore , I have two questions :
1) How can I detect what separator is used on computer ?
2) How can we actually solve this problem ?

25-10-2007 at 07:34 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 908
icon Re: Coma and dot separator for decimal numbers

Hello. Paste the following code into a module.
Private Declare Function GetLocaleInfo& Lib "kernel32" Alias _
    "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, _
    ByVal lpLCData As String, ByVal cchData As Long)

Private Const LOCALE_USER_DEFAULT& = &H400
Private Const LOCALE_SDECIMAL& = &HE
Private Const LOCALE_STHOUSAND& = &HF

' return current system's thousand separator char
' http://hjem.get2net.dk/GeWare/VBTips2.htm
Public Function ThousandSeparator() As String
    Dim r As Long, s As String
    s = String(10, "a")
    r = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, s, 10)
    ' It returns a Null Terminated string. So, in order to obtain
    ' only the bare single separator charachter, I got to use the
    ' Left$ function in the returned value
    ThousandSeparator = Left$(s, r - 1)
    ' this instruction removes the final Null char
End Function


' return current system's decimal separator char
' http://hjem.get2net.dk/GeWare/VBTips2.htm
Public Function DecimalSeparator() As String
    Dim r As Long, s As String
    s = String(10, "a")
    r = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, s, 10)
    ' It returns a Null Terminated string. So, in order to obtain
    ' only the bare single separator charachter, I got to use the
    ' Left$ function in the returned value
    DecimalSeparator = Left$(s, r - 1)
    ' this instruction removes the final Null char
End Function


Now, assuming the module name is Funx.bas, proceed as following:
    Public decsep As String

    [.....]

    decsep = Funx.DecimalSeparator

    [......]

    Dim firstnum As Double, secondnum As Double, resultnum as Double

    firstnum = CDbl(Replace(txtFirstValue.Text, decsep, ".")
    secondnum = CDbl(Replace(txtSecondValue.Text, decsep, ".")
    resultnum = firstnum * secondnum

    [......]



Hope it helps.

____________________________
Real Programmer can count up to 1024 on his fingers

26-10-2007 at 04:38 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Coma and dot separator for decimal numbers
Next Topic (Receiving "Out of memory" error message) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder