Results 1 to 15 of 15

Thread: Change Regional Settings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    145

    Change Regional Settings

    Elroy - can you help me better understand the reason behind a bit of the code that you previously posted for 'Regional settings change' (eg: decimal setting)?

    it is noted in a previous post that 'We MUST use the ANSI API version so it's an ANSI character that's used for the actual decimal character.' i am wondering what the reason is that we must use this ANSI character here? Thanks for helping me to understand. [from this post here].

    also, will this code work ok with both Win10 and Win7? Are user security settings any issue with this code to change Regional settings?

    i'm still somewhat apprehensive to change user's regional settings, even with the user knowledge/action. But there's not alot of simple alternatives.
    /Jimboat

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    145

    Re: Change Regional Settings

    Quote Originally Posted by dilettante View Post
    dilettante - i saw your VConvert routine previously and it looks terrific, if i understand correctly how it would be used. I note that a use could be "conversions of data between a user interface and data where your code assumes a fixed locale and you want to insist users work in that locale even when the user locale is an entirely different one." So can i 'convert' all data from user interfaces (eg: text boxes) and from dB records to use my 'fixed' decimal = "."?
    /Jimboat

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings

    Yes. No need to change the user's locale settings. Just use the locale you want for the things you need it for.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    145

    Re: Change Regional Settings

    Quote Originally Posted by dilettante View Post
    Yes. No need to change the user's locale settings. Just use the locale you want for the things you need it for.
    dilettante - this sounds like just the solution i'm looking for? can you show me a simple example of how to use for variable input prior to my normal code calcs with var?
    /Jimboat

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings

    Code:
    Option Explicit
    
    Private VConvert As VConvert
    
    Private Sub Command1_Click()
        With VConvert
            Text1.Text = .Convert(.Convert(Text1.Text, vbDouble) * 2.2, vbString)
        End With
    End Sub
    
    Private Sub Form_Load()
        Set VConvert = New VConvert
        VConvert.LCID = LOCALE_INVARIANT
    End Sub
    Name:  sshot1.png
Views: 206
Size:  1.3 KB
    Before click

    Name:  sshot2.png
Views: 188
Size:  1.4 KB
    After


    This should give correct results even if the user's locale has something like "," or "~" or something as its decimal point symbol.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    145

    Re: Change Regional Settings

    Dilettante- great! I’ll give it a try. Thx!
    /Jimboat

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings

    Here is something a little different.

    Say you want to accept user input but store as a String value in the database with "universal" formatting:

    Code:
    Option Explicit
    
    Private vcInvariant As VConvert
    Private vcUser As VConvert
    
    Private Sub Command1_Click()
        Label1.Caption = vcInvariant.Convert(vcUser.Convert(Text1.Text, vbDouble) * 2.2, _
                                             vbString)
    End Sub
    
    Private Sub Form_Load()
        Set vcInvariant = New VConvert
        vcInvariant.LCID = LOCALE_INVARIANT
        Set vcUser = New VConvert
        vcUser.LCID = LOCALE_USER_DEFAULT
    End Sub
    Name:  sshot.png
Views: 207
Size:  2.0 KB
    Changed my user regional formatting to Germany
    to accept numbers in that format from and
    report numbers in that format to the user,
    yet store and retrieve in INVARIANT format.

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Change Regional Settings

    Quote Originally Posted by Jimboat View Post
    Elroy - can you help me better understand the reason behind a bit of the code that you previously posted for 'Regional settings change' (eg: decimal setting)?

    it is noted in a previous post that 'We MUST use the ANSI API version so it's an ANSI character that's used for the actual decimal character.' i am wondering what the reason is that we must use this ANSI character here? Thanks for helping me to understand. [from this post here].

    also, will this code work ok with both Win10 and Win7? Are user security settings any issue with this code to change Regional settings?

    i'm still somewhat apprehensive to change user's regional settings, even with the user knowledge/action. But there's not alot of simple alternatives.
    Hi Jim,

    Ok, first, all I'm changing is the decimal (integer vs floating point portions of the number) separator. In English we use the period, whereas in French (and many other languages) the comma is used, and that caused me some big problems. If I remember correctly, it also had to do with using the Val() function (which is old and creaky, Dil's words).

    Just as a quick example of the problem:

    Code:
    
    Debug.Print Val("123.456")  ' Shows 123.456
    Debug.Print Val("123,456")  ' Shows 123
    
    As we can see, if the decimal separator is a comma, the Val() function hits it and stops reading the numeric string.

    I first ran across the problem when I made an installation of my software in Montreal (French speaking). They start getting these "stair-step" effects on some of their graphs. It took a while to track it down, but that rounding to integers was precisely the problem.

    -----------

    So Jim, you are, of course, welcome to solve the problem anyway that works for you. But, because of the volume of code I was dealing with, forcing the decimal separator character to a period was the best solution for me. And the Montreal folks were perfectly happy with that solution. It turns out they tended to use the period anyway, when writing numbers. I suppose it was just a USA influence.

    Best Regards,
    Elroy

    EDIT: Regarding requiring an ANSI character, I think that's just because I've used the ANSI version of the API declarations. I've got no idea whether Windows allows Unicode characters for the decimal separator. Personally, I've never heard of anything other than a comma or a period used for that.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings

    I'd avoid all of this anyway by storing numeric types in the database, not String values.

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Change Regional Settings

    Quote Originally Posted by dilettante View Post
    I'd avoid all of this anyway by storing numeric types in the database, not String values.
    Well, that's unavoidable in my case. Sure, for the most part, these numbers are stored in a database. However, in the motion analysis community, one of our standard files is referred to as a GCD file (gait coordinate data), and these are ASCII files. Here's a snippet out of one of those:

    Code:
    ...
    !LeftStrideLength
    916.9284
    !LeftStepLength
    475.9832
    !LeftSpeed
    833.5712
    !VideoRate
    120.0
    !LeftAnkleFlexExtAbs
    -1.285748
    -5.253628
    -7.566448
    -7.109905
    -4.878721
    -2.409862
    -0.6014383
    0.4413801
    1.022997
    1.467493
    ...
    They're a bit like INI files, but they actually go WAY back to Digital Equipment mini-computer days. They're just a "standard" we have and have never escaped. In my case, when I was writing these things, I wound up putting commas into them (when language was set to French), which wreaked all kinds of havoc.
    Last edited by Elroy; Aug 14th, 2020 at 11:35 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings

    Well you have the issue with most textual serialization/persistence formats. XML, JSON, etc., etc.

    They goofed with CSV, allowing localized formatting. Big mistake, too late to rectify.

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Change Regional Settings

    You can also use the legacy functions: Str$() and Val(). Those always deal in Earth Standard format.

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Change Regional Settings

    Quote Originally Posted by dilettante View Post
    You can also use the legacy functions: Str$() and Val(). Those always deal in Earth Standard format.
    Yeah, you're correct. With enough work, and plenty of alpha- and beta-testing, we could have fixed the problem in a better way. But, in my case, the "quick fix" was to just force the decimal (regional setting) separator.

    And yeah, for anyone starting from scratch, I'd recommend doing this in some better way that didn't involve messing with any of the regional settings (but still work regardless of what the regional settings were set to).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    145

    Re: Change Regional Settings

    Quote Originally Posted by Elroy View Post
    Hi Jim,
    Ok, first, all I'm changing is the decimal (integer vs floating point portions of the number) separator. In English we use the period, whereas in French (and many other languages) the comma is used, and that caused me some big problems. If I remember correctly, it also had to do with using the Val() function (which is old and creaky, Dil's words). As we can see, if the decimal separator is a comma, the Val() function hits it and stops reading the numeric string.
    I first ran across the problem when I made an installation of my software in Montreal (French speaking). They start getting these "stair-step" effects on some of their graphs. It took a while to track it down, but that rounding to integers was precisely the problem.
    So Jim, you are, of course, welcome to solve the problem anyway that works for you. But, because of the volume of code I was dealing with, forcing the decimal separator character to a period was the best solution for me. And the Montreal folks were perfectly happy with that solution. It turns out they tended to use the period anyway, when writing numbers. I suppose it was just a USA influence. Best Regards,
    Elroy
    Thanks, Elroy - yes, i have the very same problem that you are describing. My issue is just the treatment of 'decimal' character in some locales that don't use ".". I wish that i had a more suitable solution that didn't involve a huge volume of work, but so far, your simple solution looks like the best for me at this point. thanks again.
    /Jimboat

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