Results 1 to 7 of 7

Thread: decimal symbol

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    I like to change the decimalsymbol from Windows,
    when I start my program it must be a point - . – and
    when i close my program it must be a delimeter - , -
    Does anyone now if this is possible and how to do that ?

  2. #2
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126
    If you mean that you just need to display numeric values like currencies using a comma as the decimal symbol instead of a dot, you can use:

    Code:
    dblMyNumber = 123.45
    strMyFormattedNumber = CStr(Format(MyNumber,"#,##"))
    which means display the expression MyNumber using the user defined format "#,##".

    strMyFormattedNumber should now equal "123,45"

    If, on the other hand, you mean you want to change the system's decimal symbol for all windows programs (like in the regional settings tab of control panel), let me know and I'll post the code.



  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    If, on the other hand, you mean you want to change the system's decimal symbol for all windows programs (like in the regional settings tab of control panel), let me know and I'll post the code.

    Indeed, I mean this, I am glad if you will give me the code !

  4. #4
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Lightbulb Changing the regional settings:

    Ok Kars, here's the theory:

    Regional Settings are stored in a 'Locale'.
    To change a setting in the locale you must use the SetLocaleInfo api function and provide it with:

    the localeid (which locale's setting to change- usually the default locale)

    the hex value of the setting (in this case LOCALE_SDECIMAL or LOCALE_SMONDECIMALSEP)

    and the new value (in this case ",")

    The PostMessage api function just tells other applications that the system settings have changed.

    -----------------------------------------------------

    and here's the code:

    Code:
        'paste these into the general declarations section of your module
        Private Const LOCALE_SDECIMAL = &HE 'for numbers 
        Private Const LOCALE_SMONDECIMALSEP = &H16 'for currencies
        Private Const WM_SETTINGCHANGE = &H1A
        Private Const HWND_BROADCAST = &HFFFF& 'to tell other applications that the system settings have changed
        
        Private Declare Function SetLocaleInfo Lib "kernel32" Alias _
        "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As _
        Long, ByVal lpLCData As String) As Boolean
        
        Private Declare Function PostMessage Lib "user32" Alias _
        "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, ByVal lParam As Long) As Long
        
        Private Declare Function GetSystemDefaultLCID Lib "kernel32" _
        () As Long
    
    'paste this into the module
    Public Function ChangeDecimalSeparator(SeparatorCharacter As String)
    
             Dim dwLCID As Long
    
             'get our default locale 
             dwLCID = GetSystemDefaultLCID()
             
             'default to successful outcome
             ChangeDecimalSeparator = True
             
             'this one's for the decimal separator in the 'Number' tab of the international settings
             If SetLocaleInfo(dwLCID, LOCALE_SDECIMAL, SeparatorCharacter) = False Then
                ChangeDecimalSeparator = False
             End If
             
             'this one's for the decimal separator in the 'Currency' tab of the international settings
             If SetLocaleInfo(dwLCID, LOCALE_SMONDECIMALSEP, SeparatorCharacter) = False Then
                ChangeDecimalSeparator = False
             End If
             
             PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
             
    End Function
    
    'call the function with:
    Private Sub Command1_Click()
        'if it doesn't matter whether it works or not:
        ChangeDecimalSeparator ","
        
        'if it does:
        If ChangeDecimalSeparator(",") = False Then
            'panic
        End If
        
    End Sub
    Any problems, let me know.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    Originally posted by Kars Lensen
    If, on the other hand, you mean you want to change the system's decimal symbol for all windows programs (like in the regional settings tab of control panel), let me know and I'll post the code.

    Indeed, I mean this, I am glad if you will give me the code !
    Thanks very, very much, this works perfect !

    Is it also possible to make (on the keyboard) tempory:
    the right-arrow key -> "@"
    and the point(del) key on nummeric pad -> "," ?
    (This is for the use of a CAD program, so I will redirect the keys before I start the CAD-program, then start the program and by leaving the program set the keys back to normal.


  6. #6
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126
    So, if I understand correctly, your VB program wraps around the CAD program and simply needs to mess about with the keyboard settings to make the CAD program work properly and then reset the settings.

    I'll get back to you...

  7. #7
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126
    I don't know whether there is already an API function that can alter the keyboard map in this way, quite possibly.

    If it is not possible to change the map in a 'static' manner, it would be possible to subclass (interrupt) the message WM_KEYDOWN and then check for WK_RIGHT (the right arrow) and consume the message, then send another message with the desired key.

    Personally, I think that the first option is a much better idea, but I'm not sure where to look.

    Anyone know a suitable API?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width