Announcement

Collapse
No announcement yet.

Can this country info code be ported to Win32?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can this country info code be ported to Win32?

    Guys and Dolls,

    Windows does not always give the correct format for a short date.
    DOS did, as far as I remember. My question is: can Windows read the information in the Dos file COUNTRY.SYS?
    In other words, can the following code be ported to the Win32 platform?

    Code:
    '                   Source code: PowerBASIC for DOS
    '
    '           Author: [email protected]
    ' Copyright status: Public Domain
    ' FUNCTIONs to get country code and
    '         country specific delimiters for date, time and numbers
    
    $COMPILE EXE
    ' -----------------------------------------------------------------------
    ' CountryInfo - returns a string with the following information:
    ' First byte (= string's ASCII) is either 0, 1 or 2
    '     0: date format = mdy (American)
    '     1: date format = dmy (European)
    '     2: date format = ymd (Asian or Japanese)
    
    ' Char  8: country specific decimal point
    ' Char 10:                  thousand separator
    ' Char 12:                  date separator
    ' Char 14:                  time separator
    
    FUNCTION CountryInfo AS STRING
      buffer$ = SPACE$(64)                             ' prepare buffer
      REG 8, STRSEG(buffer$)                           ' DS = segment
      REG 4, STRPTR(buffer$)                           ' DX = offset
      REG 1, &H3800                                    ' AX = service
      CALL INTERRUPT &H21
      FUNCTION = buffer$                               ' buffer filled
    END FUNCTION
    
    ' main
    CLS
      buff$ = CountryInfo
      code% = REG(2)
      formt% = ASC(buff$)
      dd$ = MID$(buff$, 12, 1)
      pbDate$ = DATE$
      REPLACE "-" WITH dd$ IN pbDate$
      PRINT "Your country code is: "; TRIM$(STR$(code%))
      PRINT "The date delimiter in your country is: "; CHR$(34, 32); dd$; CHR$(32, 34)
      SELECT CASE formt%
        CASE 0
          PRINT "Date format is: MM DD YYYY"
        CASE 1
          PRINT "Date format is: DD MM YYYY"
          pbDate$ = MID$(pbDate$, 4, 3) + LEFT$(pbDate$, 3) + MID$(pbDate$, 7)
        CASE 2
          PRINT "Date format is: YYYY MM DD"
          pbDate$ = MID$(pbDate$, 7) + dd$ + LEFT$(pbDate$, 3) + MID$(pbDate$, 4, 2)
      END SELECT
      PRINT "So a short date in Windows should look like this: "; pbDate$
    END


    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

  • #2
    how about using the getdateformat() api? possibly with the aide of the enumdateformats() api?

    1 year ago (almost to the day), you took part in a discussion on this very topic in http://www.powerbasic.com/support/pb...ead.php?t=2462

    ------------------
    lance
    powerbasic support
    mailto:[email protected][email protected]</a>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Originally posted by Lance Edmonds:
      How about using the GetDateFormat() API?
      Lance,

      As I said, Windows does not always return the correct short date.
      Therefore this is what I'm doing now:
      1. run my Dos app and save the result to a file
      2. start my Win app, read the file and set the short date format according to what DOS reported.

      If there is a possibility to perform task #1 under Windows, then I can simply add a few code lines to my Win app.
      Furthermore: the DOS app only returns correct results when the country code is set appropriately in config.sys, a file that is highly neglected by Windows users.



      ------------------
      mailto:[email protected][email protected]</A>
      www.basicguru.com/zijlema/

      Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
      http://zijlema.basicguru.eu
      *** Opinions expressed here are not necessarily untrue ***

      Comment


      • #4
        Egbert --
        > As I said, Windows does not always return the correct short date.

        If Windows returns another result that you want to see, this doesn't mean "incorrect".
        For example, for russian language Win2000 offers 5 formats.
        Four from them are actually used dd.MM.yyyy dd.mm.yy dd/mm/yy d.m.yy
        One (yyyy-MM-dd) is really strange.

        Without lpformat Windows selects a format according Regional settings.
        If to use lpformat, you can be independent at all.

        > Country.sys

        DOS settings are indepent of Windows settings and can conflict.

        Example: Toshiba notebooks, which you can buy in Russia, have pre-installed English Windows release.
        Owners typically change settings in config.sys only (to russian).
        This allows normally work with DOS programs in full screen mode.
        Meanwhile Regional settings typically remains English (anyway will be incorrect code page for console programs in "window" mode).
        Interesting which settings is possible to name correct for Windows programs ?

        You ask, is it possible to execute Int 21h in 32-bit program.
        Actually it's very interesting question.
        Guess, that Windows uses undocumented API functions to switch real - protected mode.
        I think so, because there are different types of processors and a code should be enough long.
        It's not simple changing of PE bit in cr0 register.

        [This message has been edited by Semen Matusovski (edited July 17, 2001).]

        Comment


        • #5
          In what way does Windows not return the correct format for a short date?

          I doubt that COUNTRY.SYS has any relevance to Windows. You might check into
          Windows internationalization functions such as GetSystemDefaultLCID.


          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            Originally posted by Tom Hanlin:
            In what way does Windows not return the correct format for a short date?
            Maybe, Tom, it's merely a matter of what one expects after so many years of DOS-programming.
            Anyhow, with Regional Settings set to "Dutch (standard)" Windows95 returns "dd-mm-yy" (2 figures for year), while my above DOS code returns "dd-mm-yyyy".
            The format returned by DOS is correct in my opinion. As far as I can test, German settings also return a different short date than DOS used to return (Thomas Gohel, if you read this message, please enlighten me).
            Note that Regional Settings in Control Panel may be modified by the user. The settings for DOS, loaded from COUNTRY.SYS by CONFIG.SYS are system settings and thus no subject of change.

            Whatever, wrong or just different, I like my short dates being displayed the way DOS displays file dates when executing the DIR command.

            ------------------
            mailto:[email protected][email protected]</A>
            www.basicguru.com/zijlema/

            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
            http://zijlema.basicguru.eu
            *** Opinions expressed here are not necessarily untrue ***

            Comment


            • #7
              Seems like this is a Windows configuration issue, not actually a bug of any sort.
              The best solution, then, may be to change your "short date" setting in your Windows
              configuration.

              ------------------
              Tom Hanlin
              PowerBASIC Staff

              Comment


              • #8
                Tom,

                That's not the issue. On my own computer I did change the short date format already. Of course!
                The point is, that my program also will run on other computers (I hope).
                What I want to achieve is that the application retrieves and displays short dates as 'prescribed' bij DOS.
                Is that possible? In other words, is there a trick to call INT 21 from within Windows32.
                Semen Matusovski calls it an interesting challenge to figure that out.

                ------------------
                mailto:[email protected][email protected]</A>
                www.basicguru.com/zijlema/

                Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                http://zijlema.basicguru.eu
                *** Opinions expressed here are not necessarily untrue ***

                Comment


                • #9
                  Originally posted by Egbert Zijlema:
                  What I want to achieve is that the application retrieves and displays short dates as 'prescribed' bij DOS.
                  As an end user, *I want* Windows applications to honour the way I have configured my machine to display dates.
                  Surely, that is the whole point of Windows "Regional Settings" and GetDateFormat().

                  (Unless of course, you are putting dates into log files/lists etc and need to be able to sort them. Then it is quite acceptable to force them to display as YYYY-MM-DD or whatever)



                  [This message has been edited by Stuart McLachlan (edited July 17, 2001).]

                  Comment


                  • #10
                    I am not sure I understood the problem. I think Windows returns the correct date/time regardless the local settings and allows you to format it as you want.
                    Consider this code as a sample to prove that:

                    $COMPILE EXE
                    $INCLUDE "WIN32API.INC"
                    FUNCTION PBMAIN()
                    LOCAL st AS SYSTEMTIME
                    LOCAL t AS ASCIIZ * 64
                    LOCAL d AS ASCIIZ * 64
                    GetLocalTime st
                    GetDateFormat %LOCALE_SYSTEM_DEFAULT, %LOCALE_NOUSEROVERRIDE, st, BYVAL %NULL, d, 64
                    GetTimeFormat %LOCALE_SYSTEM_DEFAULT, %LOCALE_NOUSEROVERRIDE, st, BYVAL %NULL, t, 64
                    MSGBOX "Using local settings: " & d & " " & t & $CRLF & _
                    "Formatted per your wish: " & FORMAT$(st.wMonth, "00") & " " & FORMAT$(st.wDay, "00") & " " & FORMAT$(st.wYear) & " " & FORMAT$(st.wHour, "00") & ":" & FORMAT$(st.wMinute, "00") & ":" & FORMAT$(st.wSecond, "00"), _
                    %MB_OK, "The time ON this machine"
                    END FUNCTION

                    Regards,

                    Peter Redei

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

                    Comment


                    • #11
                      Okay folks,

                      Forget the DOS-routine. Initially use Power Basic's DATE$ for the short date format, but find its format and separator using the Windows API GetLocaleInfo.
                      Just posted my code to the Source Code Forum.

                      Thanks to everyone participating in this discussion.
                      And maybe, Semen will come with a Windows routine for calling INT 21h?

                      Regards,

                      ------------------
                      mailto:[email protected][email protected]</A>
                      www.basicguru.com/zijlema/

                      [This message has been edited by Egbert Zijlema (edited July 18, 2001).]

                      Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                      http://zijlema.basicguru.eu
                      *** Opinions expressed here are not necessarily untrue ***

                      Comment


                      • #12
                        I'm not sure your users will thank you for forcing your own date preferences on them,
                        but that's your decision to make.

                        ------------------
                        Tom Hanlin
                        PowerBASIC Staff

                        Comment


                        • #13
                          I've not spent a lot of time looking into this, but the code in the Source Code forum reports my Local Date format as MM/DD/YY, but my locale settings should make it show as DD/MM/YY.

                          ------------------
                          Lance
                          PowerBASIC Support
                          mailto:[email protected][email protected]</A>
                          Lance
                          mailto:[email protected]

                          Comment


                          • #14
                            Originally posted by Tom Hanlin:
                            I'm not sure your users will thank you for forcing your own date preferences on them,
                            but that's your decision to make.

                            Tom,
                            I'm not forcing anyone. My application, whatever it is, does not modify settings. Only when it displays calendar dates, it uses this format.


                            ------------------
                            mailto:[email protected][email protected]</A>
                            www.basicguru.com/zijlema/

                            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                            http://zijlema.basicguru.eu
                            *** Opinions expressed here are not necessarily untrue ***

                            Comment


                            • #15
                              egb
                              Originally posted by Lance Edmonds:
                              I've not spent a lot of time looking into this, but the code in the Source Code forum reports my Local Date format as MM/DD/YY, but my locale settings should make it show as DD/MM/YY.

                              Lance,

                              That looks impossible to me. My source only rebuilds Power Basic's DATE$, which is "mm-dd-yyyy" initially.
                              It may shuffle month, day and year, even alter the separator, but not the length of the string.


                              ------------------
                              mailto:[email protected][email protected]</A>
                              www.basicguru.com/zijlema/

                              Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                              http://zijlema.basicguru.eu
                              *** Opinions expressed here are not necessarily untrue ***

                              Comment


                              • #16
                                The length is the same.... it is just the MM and DD elements which are reversed.

                                When I have some time, I'll try to look into it.

                                ------------------
                                Lance
                                PowerBASIC Support
                                mailto:[email protected][email protected]</A>
                                Lance
                                mailto:[email protected]

                                Comment

                                Working...
                                X