Consulting

Results 1 to 10 of 10

Thread: Dots to comma in userform

  1. #1
    VBAX Regular
    Joined
    Nov 2010
    Posts
    14
    Location

    Dots to comma in userform

    Hi,

    I have a really annoying problem which I just can't solve on my own. I hope some of you more experienced VBA programmers can help me out!

    Ok, the thing is that I have a userform with some textboxes and comboboxes. Some of the boxes have predetermined values and some are left empty for the user to fill out.
    In the beginning the decimalseparators were commas just as I want them to be but suddenly for a reason which is unknown to me the decimalseparators changed to dots. The result is that my code now perceives the numbers as if there are no decimal separators at all and I am getting completely wrong results.

    I really don't understand what is going on... Maybe I have accidently hit a combination on the keyboard which has changed some settings...?

    Does anybody know how to solve my problem?

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Have you changed the number format in some way?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    If you are using Windows 7 it may not be an excel problem. Apparently Windows 7 can get its regional settings confused but it's an easy fix; change your regional settings then change them back.

    I only know one way that you intentionally override the system default and it's not something you could do accidentally. Have a look at This.
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    You can check the regional settings, in this case the decimalseparator, using:

    [vba]
    sub M_snb()
    msgbox Application.International(3)
    end sub
    [/vba]

    @Teeroy
    There's a very simple oneliner to change the regional settings....

  5. #5
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Hi @SNB, I didn't mention Application.International because as far as I was aware it's read only and @Ako wanted to know how the decimal separator could have changed. As for the one-liner, hit me with it (I've seen you do some pretty funky things with a one-liner, though I don't know that I'd call them all simple ). Some of your one-liners take some working out but I learn a thing or three in the process.
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    An API or registry method can be used to change the settings. In xp: Start > Settings > Control Panel > Regional and Language Options > Customize.

    Of course the controls are string based so how a number is interpreted can trip you up.
    Last edited by Kenneth Hobs; 11-05-2012 at 07:55 AM.

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    @teeroy

    I thought it to be worth while to check first whether any changes in the regional settings had taken place before assuming they had.

    To retrieve / chnage international settings; in this case the decimal separator:

    [vba]
    Sub M_snb()
    with CreateObject("wscript.shell")
    msgbox .regread("HKEY_CURRENT_USER\Control Panel\International\sDecimal")
    msgbox .regread("HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Options\de cimalseparator")

    ' changing:

    .regwrite "HKEY_CURRENT_USER\Control Panel\International\sDecimal", "|"
    .regwrite "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Options\decimalsepa rator", "|"
    end with
    end sub
    [/vba]
    Last edited by snb; 11-05-2012 at 07:36 AM.

  8. #8
    VBAX Regular
    Joined
    Nov 2010
    Posts
    14
    Location
    Hi,

    I have tried all the solutions that you have suggested, but so far nothing works

    All the checks I have made based on your good advises showed that my computer is setup to use "," as the decimalseparator and "." as the thousandseparator.

    Just to make sure that it is not my code which is the problem I have tried following:

    1: I have created a userform in a new document. The userform contained a textbox which I gave an initial value of 2,4.
    This is still displayed as 2.4 when I am running the userform.

    2: I have tried to change the national settings so that the decimalseparator is ".".
    This works very well and my code are now getting the correct results.

    Of course I could just continue to use "." as decimalseparator but since we in Denmark use "," I would really like my code to work for our national settings.

    Do any of you have any alternative ideas?

  9. #9
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You need to post your workbook or all the code for the userform for us to troubleshoot.

    As I said, a value of "2,4." is a string and should not be changing by whatever setting you have. Now putting a textbox string value into a numeric cell type is another matter.

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    You probably are using 'linkedcell'. Do not use that.

Posting Permissions

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