Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Regional Date Settings (2000/XP)

    I am working with a shared database and not sure if all users have the same regional date settings. I know I could go around and make sure that they all have the same format, but I am wondering if there is a way of determining their preferred format (dd/mm/yyyy or mm/dd/yyyy) by looking at the regional settings.

    The users have to be consistent or I have to know what the setting is otherwise my calendar control popup form does not work.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Regional Date Settings (2000/XP)

    Are the users all in the same geographic area? If so, you can always use input masks to force them to use a particular format for input. We use a medium date format for that purpose dd-mmm-yyyy. We've found that anyone can read the date that way and there is no confusion between 1 Feb and 2 Jan as there might otherwise be. You can read regional date setting information from the iDate value in the HKey_Current_UserControlPanelInternational key, but you have to interpret the results:


    <table border=1><td>0</td><td>mm/dd/yy </td><td>1</td><td>dd/mm/yy </td><td>2</td><td>yy/mm/dd </td></table>

    The tricky part is that the separation characters are irrelevant to the registry, so it doesn't care whether your date is formatted with slashes, dashes, periods, or anything else. It only concerns itself with the sequence of day month and year in the date. In any case, you still have to use month-day-year format in SQL and in other things like domain aggregate where expressions.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Regional Date Settings (2000/XP)

    Thanks Charlotte. They are in the same regional area. The problem is that they would prefer not to have the format dictated to them for input (even though most of them use mm/dd/yy. The exact regional setting re the separators is not important. It is the sequence of the date that concerns me so access to the iDate value will give me that, and I can use an If condition to correctly format what I pass back from the calendar popup form. Two more questions that I have just thought of.

    1) This is a database residing on a server. Whose or Which regional settings dictate the input format of the date, the users computer regional settings or the server's regional setings?

    2) Assuming it is the users station then I can use the iDate value to dictate which way around I pass the date back to the input field. In which case can you tell me explicitly how to access the iDate value.

    I know this sounds horrible as the potential for confusion amongst the users is high. I am going to try and persuade them to standardize, but just in case, I want to be prepared.

    Peter <img src=/S/please.gif border=0 alt=please width=31 height=23>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Regional Date Settings (2000/XP)

    Whatever the setting is on the user's computer is what controls it, unless possibly they're running Citrix or Terminal Server. I have no experience with that setup, so I can't say. Don't get confused between an input mask and a display format. It is not necessary for the user to enter the date in a particular format to display it that way. However, in this case, you're going to have to enforce an input mask, whether they like it or not because if one uses day-month-year and another uses month-day-year and still another uses year-month-day, you will find it impossible to "interpret" the date entered and to massage it.

    As for reading the IDate value, it requires the use of API calls to open the registry key "HKEY_CURRENT_USERControl PanelInternational" and to return the iDate value. You're going to be working with the RegOpenKeyEx and RegQueryValueEx to get the value, but I haven't looked too hard for a wrapper application for this, since it's the kind of code you wade through and build once and then use ever after. We use it in our applications at work, but I don't have the code at hand here at home. Maybe someone else can point you at some code that will help.
    Charlotte

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Regional Date Settings (2000/XP)

    As Charlotte noted, you can use the Windows RegOpenKeyEx and RegQueryValueEx API functions to retrieve Registry settings. See attached text file (exported code module) for examples of use with some wrapper functions. The user-defined GetRegVal function can be used for both String (REG_SZ) and Long (REG_DWORD) values (note: all the Control Panel International settings are saved as strings). A wrapper function, GetRegValString, specifically is used for retrieving string values; this function calls GetRegVal which in turn calls the actual API's and returns either success or an error code; an empty string buffer is passed to GetRegVal by reference. If the call is successful the buffer is filled with the string value in question. Examples of use (on WIN XP system located in US):

    ? GetRegValString(HKCU, "Control PanelInternational", "iDate")
    0
    ? GetRegValString(HKCU, "Control PanelInternational", "sShortDate")
    M/d/yyyy
    ? GetRegValString(HKCU, "Control PanelInternational", "sLongDate")
    dddd, MMMM dd, yyyy
    ? GetRegValString(HKCU, "Control PanelInternational", "sDate") ' date separator
    /
    ? GetRegValString(HKCU, "Control PanelInternational", "sCountry")
    United States
    ? GetRegValString(HKCU, "Control PanelInternational", "sLanguage")
    ENU
    ? GetRegValString(HKCU, "Control PanelInternational", "sTimeFormat")
    h:mm:ss tt

    To use attachment in your own project, rename text file with ".BAS" extension and import from VB Editor (Import File...). Use Regedit.exe or other Registry editor tool to determine the names of other values you may need to retrieve from the International settings subkey, or elsewhere in Registry. If you need to retrieve DWORD values, you can write a similar wrapper function for that purpose; instead of passing an empty string buffer to GetRegVal, you'd pass an empty Long variable for the varData parameter.

    HTH
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Regional Date Settings (2000/XP)

    That's very handy, Mark. Is it your own work, I didn't notice your name in there? <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Regional Date Settings (2000/XP)

    Many thanks to both of you for your feedback. In retrospect I don't think I was very clear in how the forms were working. The form the user sees allows the input of a date in any format and I allow the system to dictate how it interprets that date. In other words there is no Input Mask. the format is set to Medium Date. Where I was having a problem is that if the user double clicks the field a date select popup form appears (rather like the MS Date & Time Picker). The problem was occurring here in the format of the date selected in the popup form. This format was getting confused between month and day with the low numbers (i.e. it passed the result back to the original control in a format that did not agree to the local machine settings. Use of the iDate will allow for variability but is probably not the best method. I am going to try and enforce a consistency in the regional settings on all computers as this has much broader benefits in terms of allowing the movement of personnel from machine to machine without having to re-learn how they enter dates etc.

    Again many thanks for you input and I will tuck Mark's code to one side for future reference as it looks very useful.

    Peter

  8. #8
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Regional Date Settings (2000/XP)

    No, not entirely - I'm not smart enough to figure some of this stuff out without "professional assistance". The API function & constant declarations used in example were adapted from another project, which were in turn adapted, with some modifications, from sample code provided with the Access Developer's Handbook, Vol I (A2K edition) . The wrapper functions I managed to figure out myself by studying the examples from the ADH. For anyone working with Registry API's in Access or VB/VBA I'd recommend the relevant sections of chapters 16 & 17 of ADH Vol 1 as a good starting point, along with Dan Appleman's Guide to the Win32 API, another reference I always consult when working with Windows API's, Registry-related or not, to make sure I'm not doing anything stupid (which is not hard to do when using the API).

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Regional Date Settings (2000/XP)

    I know exactly what you mean. <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15> That's why I swear by http://www.allapi.net. Their examples are fully formed and you can copy and paste them quite easily without laboriously recreating the types and declarations in your own code.
    Charlotte

  10. #10
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: API Resources

    Yes, I have AllAPI.net bookmarked, though unfortunately they discontinued any updates to the site as of April 2002. One of the best online resources I've found for working with API's & other advanced VB techniques is VBnet Visual Basic Developers Resource Centre. As the site's name does not imply, it is not a site dedicated to VB.NET, but to "classic" VB (the site's name predated the advent of .NET and they were loathe to change the name once .NET reared its ugly head (joke)). As noted on home page, the site endeavors to provide "the enhanced functionality of the win32 api to intermediate and advanced visual basic developers using 'VBClassic'." And (emphasized): "Note: this site does not contain nor provide code for VB.NET." This is the type of site that will help make you look a lot smarter than you are (not hard in my case) when you adapt some of the sample code for your own projects - I almost hesitate to provide a link - I feel like I'm giving away a well-kept secret - I guess the VBnet name is misleading.... You'll find a lot of stuff here you won't find elsewhere, like networking API's introduced with WIN 2K, etc., and examples that go beyond simplistic examples found elsewhere. The code is reliable and very well documented, with copious comments, etc., and the site is updated regularly.

    Another online resource for API stuff is to go to the source, as it were: MSDN Platform SDK: Windows API Reference. On the other hand, some of the worst API code I've seen can be found in poorly documented MSKB articles. I don't know how many times I copied sample code from a MSKB article & got buggy or unreliable results. I think some of the articles were updated from the 16-bit API version with a few "minor details" omitted....

  11. #11
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: API Resources

    >>>>(the site's name predated the advent of .NET and they were loathe to change the name once .NET reared its ugly head<<<<<

    Do you think they could sue Microsoft? I recall a recent story about a chap called

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: API Resources

    The young man's name was Michael Rowe, and Microsoft backed off with egg on their face. As a matter of fact, Microsoft couldn't use Office.Net because someone else had prior claim to that name. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

Posting Permissions

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