Announcement

Collapse
No announcement yet.

Get MMDD string logic not working?

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

  • Get MMDD string logic not working?


    Here on this sample I enter 0233 and get 1B instead of 2B. Problem ?

    Been trying all kinds of more,less logic and no good results.

    My month logic works OK so did not show any code for that?

    This is suppose to check month day entrey . Leap year? Have not figured that out.

    K=TRIM$(MID$(DATE1,1,2)) : NN2=VAL(MID$(DATE1,3,2)) ' <<<< problem with this line???

    Code:
    #COMPILE EXE
    '#INCLUDE "WIN32API.INC"
    
    GLOBAL hDlg AS DWORD , TEXT1 AS STRING
    
    CALLBACK FUNCTION DIALOG2 AS LONG
    LOCAL K, DATE1 AS STRING, NN, NN2 AS LONG
    
    CONTROL GET TEXT hDlg, 201 TO DATE1
    
    K=TRIM$(MID$(DATE1,1,2)) : NN2=VAL(MID$(DATE1,3,2))
    
    ? STR$(VAL(K))+" "+STR$(NN2)
    
    IF VAL(K)=1 AND NN2>0 AND NN2=<31 THEN ? "1A": GOTO CONT1 ELSE ? "1B": GOTO EXITT 'JAN 31
    IF VAL(K)=2 AND NN2>0 AND NN2=<29 THEN ? "2A": GOTO CONT1 ELSE ? "2B": GOTO EXITT 'FEB 29
    
    CONT1:
    
    EXITT:
    CONTROL SET FOCUS hDlg, 201
    END FUNCTION
    
    FUNCTION PBMAIN() AS LONG
    DIALOG NEW 0, "Dialog 1",,,300,300, %WS_SYSMENU, 0 TO hDlg
    LOCAL result AS LONG
    
    CONTROL ADD LABEL, hDlg,400,"DIALOG1 enter date MMDD. : " , 70, 210, 120, 15
    CONTROL ADD LABEL, hDlg, 200 ,"TEXTBOX" ,120, 150, 80, 15,
    CONTROL ADD TEXTBOX, hDlg, 201 ,"" , 50, 230, 80, 15,
    CONTROL ADD BUTTON, hDlg, 100 ,"&1 DONE" ,140, 230, 50, 15, CALL DIALOG2 ' DONE1
    CONTROL ADD BUTTON, hDlg, 101 ,"&0 Cancel" ,200, 230, 50, 15, 'CALL XXXX
    CONTROL SET FOCUS hDlg, 201
    
    DIALOG SHOW MODAL hDlg TO result
    END FUNCTION
    Robert

  • #2
    Yes, because VAL(K) is not 1, so ELSE in that line will choose "1B". Try something like this instead:
    '
    Code:
      SELECT CASE VAL(K)
      CASE 1 : IF (NN2>0 AND NN2=<31) THEN ? "1A": GOTO CONT1 ELSE ? "1B": GOTO EXITT 'JAN 31
      CASE 2 : IF (NN2>0 AND NN2=<29) THEN ? "2A": GOTO CONT1 ELSE ? "2B": GOTO EXITT 'FEB 29
      END SELECT
    '

    Comment


    • #3
      BTW, had this old one for leap year test in my drawers. Think it originates from some old VB code.
      '
      Code:
      FUNCTION isLeapYear(Year AS LONG) AS LONG      
        IF ((Year MOD 4) = 0) AND _
           ((Year MOD 100) > 0) OR _
           ((Year MOD 400) = 0) THEN FUNCTION = -1
      END FUNCTION
      '

      Comment


      • #4
        Magic numbers, single character variable names, lots of GOTOs, multi-instruction lines ?
        Makes your code hard to understand and therefore people are less likely to want to help you to debug it.

        Please start using a more modern programming style.

        Your problem is:

        Code:
        ' Where DATE1 = "0233"
        IF VAL(K)=1 AND NN2>0 AND NN2=<31 THEN 'VAL(K) =2 so goto ELSE!!!!
            ? "1A"
             GOTO CONT1
        ELSE
            ? "1B"
            GOTO EXITT
        END IF
        I'm not sure what the purpose of your code is, but the PowerTime object can probably do all of your date manipulation including leap years, parsing day/month/year etc

        Comment


        • #5
          Borje you code worked.

          leap year problem,
          using leap year , do not understand

          enter 02022020 and year=0 'should be leap year
          enter 02022021 and year=0 'not leap year should be -1?

          stuart, trying to verify user input for MM DD and YYYY
          your code did not work

          thank both for your help

          Code:
          #COMPILE EXE
          '#INCLUDE "WIN32API.INC"
          
          GLOBAL hDlg AS DWORD , TEXT1 AS STRING
          
          
          FUNCTION isLeapYear(Year AS LONG) AS LONG
          IF ((Year MOD 4) = 0) AND _
          ((Year MOD 100) > 0) OR _
          ((Year MOD 400) = 0) THEN FUNCTION = -1
          END FUNCTION
          
          CALLBACK FUNCTION DIALOG2 AS LONG
          LOCAL K, DATE1 AS STRING, NN, NN2, NN3, Year AS LONG
          
          CONTROL GET TEXT hDlg, 201 TO DATE1
          
          K=TRIM$(MID$(DATE1,1,2)) : NN2=VAL(MID$(DATE1,3,2)) : NN3=VAL(MID$(DATE1,5,4))
          
          
          ? STR$(VAL(K))+" "+STR$(NN2)+" "+STR$(NN3) 'LEAP YEARS 2020 2024 2028 2032 2036 2040 2044 FOR TEST
          
          SELECT CASE VAL(K)
          CASE 1 : IF (NN2>0 AND NN2=<31) THEN ? "1A": GOTO CONT1 ELSE ? "1B": GOTO EXITT 'JAN 31
          CASE 2 : IF ((Year MOD 4) = 0) AND _
          ((Year MOD 100) > 0) OR _
          ((Year MOD 400) = 0) THEN FUNCTION = -1
          CALL isLeapYear(NN3) : ? STR$(Year)+" Year"
          IF (NN2>0 AND NN2=<29) THEN ? "2A": GOTO CONT1 ELSE ? "2B": GOTO EXITT 'FEB 29
          
          CASE 3 : IF (NN2>0 AND NN2=<29) THEN ? "3A": GOTO CONT1 ELSE ? "3B": GOTO EXITT 'MAR 29
          CASE 4 : IF (NN2>0 AND NN2=<29) THEN ? "4A": GOTO CONT1 ELSE ? "4B": GOTO EXITT 'APR 29
          END SELECT
          
          
          CONT1:
          
          EXITT:
          CONTROL SET FOCUS hDlg, 201
          END FUNCTION
          
          FUNCTION PBMAIN() AS LONG
          DIALOG NEW 0, "Dialog 1",,,300,300, %WS_SYSMENU, 0 TO hDlg
          LOCAL result AS LONG
          
          CONTROL ADD LABEL, hDlg,400,"DIALOG1 enter date MMDDYYYY. : " , 70, 210, 120, 15
          CONTROL ADD LABEL, hDlg, 200 ,"TEXTBOX" ,120, 150, 80, 15,
          CONTROL ADD TEXTBOX, hDlg, 201 ,"" , 50, 230, 80, 15,
          CONTROL ADD BUTTON, hDlg, 100 ,"&1 DONE" ,140, 230, 50, 15, CALL DIALOG2 ' DONE1
          CONTROL ADD BUTTON, hDlg, 101 ,"&0 Cancel" ,200, 230, 50, 15, 'CALL XXXX
          CONTROL SET FOCUS hDlg, 201
          
          DIALOG SHOW MODAL hDlg TO result
          END FUNCTION
          Robert

          Comment


          • #6
            Originally posted by Robert Alvarez View Post
            Borje you code worked.

            leap year problem,
            using leap year , do not understand

            enter 02022020 and year=0 'should be leap year
            enter 02022021 and year=0 'not leap year should be -1?
            That's because of the way you are using it


            stuart, trying to verify user input for MM DD and YYYY
            your code did not work
            Of course it didn't work, it was your code, just broken into logical lines to made easier to follow and commented to show where your error was.

            Comment


            • #7
              Code:
              CASE 2 :[COLOR=#e74c3c] IF ((Year MOD 4) = 0) AND _ ((Year MOD 100) > 0) OR _ ((Year MOD 400) = 0) THEN FUNCTION = -1
              CALL isLeapYear(NN3) :[/COLOR]  _
              ? STR$(Year)+" Year" IF (NN2>0 AND NN2=<29) THEN ? "2A": GOTO CONT1 ELSE ? "2B": GOTO EXITT 'FEB 29
              The code in red is doing nothing for you variable "Year" is always zero here. You call function isLeapYear but do nothing with what it returns.


              I think this is what you are looking for.
              Code:
              CASE 2 : ? STR$(isLeapYear(NN3))+" Year"
              IF (isLeapYear(NN3)= -1 AND NN2>0 AND NN2=<29) OR (isLeapYear(NN3)= 0 AND NN2>0 AND NN2=<28) THEN ? "2A" _
              : GOTO CONT1 ELSE ? "2B": GOTO EXITT 'FEB 29

              Comment


              • #8
                Suggested solution. Much simpler logic and easier to follow. Annotated with style suggestions

                '
                Code:
                #COMPILE EXE
                #DEBUG ERROR ON  ' Include while developing.  Remove for release version
                #DEBUG DISPLAY ON ' Include while developing.  Remove for release version
                #DIM ALL  ' always use!!!!
                
                ' All variables prefixed so that you immediately see their type
                ' All globals prefixed with "g" to avoid confusion with local variables
                GLOBAL ghDlg AS DWORD
                
                'Use meaningful equates for controls, not mystery numbers
                'that way you can always tell what control you are working with
                ENUM ctrls SINGULAR
                   IDC_lbl1 = 1001
                   IDC_lbl2
                   IDC_txt1
                   IDC_btnDone
                   IDC_btnCancel
                END ENUM
                
                FUNCTION isLeapYear(Year AS LONG) AS LONG
                IF ((Year MOD 4) = 0) AND _
                ((Year MOD 100) > 0) OR _
                ((Year MOD 400) = 0) THEN FUNCTION = -1
                END FUNCTION
                
                CALLBACK FUNCTION CBbtnDone AS LONG   ' Note function name - this is a callback for one control. (see comment in PBMain)
                    LOCAL strDATE,strResult AS STRING
                    LOCAL lngDay, lngMth, lngYear AS LONG
                    DIM lngDays(1 TO 12) AS LONG
                    DIM strMths(1 TO 12) AS STRING
                    ARRAY ASSIGN lngDays() = 31,28,31,30,31,30,31,31,30,31,30,31  'days in month in normal year
                    ARRAY ASSIGN strMths() = " Jan"," Feb"," Mar"," Apr"," May"," Jun"," Jul"," Aug"," Sep"," Oct"," Nov"," Dec"
                
                    'Always test for what message you are handling in a callback
                    'Windows passes lots of messages around
                    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                
                        CONTROL GET TEXT ghDlg,%IDC_txt1 TO strDate
                         ' or get in the habit of using CB.HNDL and CB.CTL where possible  In many cases it's preferable
                        'CB.HNDL would avoid having to declare ghDLg as global   
                 
                        'Convert string date parts to numbers
                        lngMth =  VAL(MID$(strDATE,1,2))
                        lngDay =  VAL(MID$(strDATE,3,2))
                        lngYear = VAL(MID$(strDATE,5,4))
                      
                        'initial reasonableness checks
                        IF lngDay < 1 THEN ? "Invalid Day"& STR$(lngDay) : EXIT FUNCTION
                        IF lngMth < 1 OR lngMth > 12 THEN ? "Invalid Month" & STR$(lngMth) : EXIT FUNCTION
                
                        'deal with leap years
                        IF isleapyear(lngYear) THEN lngDays(2) = 29
                
                       'the complete process of checking
                        IF lngDay <= lngDays(lngMth) THEN
                            strResult = STR$(lngDay) & strMths(lngMth) & STR$(lngYear)
                        ELSE
                            strResult = "Invalid Date" & STR$(lngDay) & strMths(lngMth) & STR$(lngYear)
                        END IF
                
                        ? strResult
                        CONTROL SET FOCUS ghDlg, %IDC_txt1
                    END IF
                END FUNCTION
                
                FUNCTION PBMAIN() AS LONG
                    DIALOG NEW 0, "Dialog 1",,,300,300, %WS_SYSMENU, 0 TO ghDlg
                    LOCAL result AS LONG
                
                    CONTROL ADD LABEL, ghDlg,%IDC_lbl1,"DIALOG1 enter date MMDDYYYY. : " , 70, 210, 120, 15
                    CONTROL ADD LABEL, ghDlg,%IDC_Lbl2 ,"TEXTBOX" ,120, 150, 80, 15,
                    CONTROL ADD TEXTBOX, ghDlg, %IDC_txt1 ,"" , 50, 230, 80, 15,
                    'Give single control callbacks names which identify then. NOT the Dialog name!
                    CONTROL ADD BUTTON, ghDlg, %IDC_btnDone ,"&1 DONE" ,140, 230, 50, 15, CALL CBbtnDone ' i
                    CONTROL ADD BUTTON, ghDlg, %IDC_btnCancel ,"&0 Cancel" ,200, 230, 50, 15, 'CALL XXXX
                    CONTROL SET FOCUS ghDlg, %IDC_txt1
                
                    DIALOG SHOW MODAL ghDlg TO result
                END FUNCTION
                '

                Comment


                • #9
                  Rod , that worked thanks
                  Stuart , your code works OK, and thanks for you help.
                  Robert

                  Comment


                  • #10
                    Yes, isLeapYear should be fed a 4 digit year YYYY. The formula is "a year which is an integer multiple of 4, except for years evenly divisible by 100 (century shifts) which are not leap years unless evenly divisible by 400).
                    This means that for example year 2000 was a leap year, but 2100, 2200 2300 will not be, while 2400 will be, etc. (divisible by 400)

                    Added - always good to understand code/functions, that's why I posted this. See also MOD operator in PB Help).

                    Comment


                    • #11
                      I wonder why you still bother with your own proprietary date code, if PB provides the PowerTime object? It even has a IsLeapYear method ...

                      Comment


                      • #12
                        I wonder why you still bother with your own proprietary date code, if PB provides the PowerTime object? It even has a IsLeapYear method ...
                        I second that!

                        Displays all members 7-days apart. StringBuilder is not required.

                        Code:
                        %Hundred_Nanoseconds_Per_Day = 864000000000
                        
                        MACRO sbCR(parm1)
                          sb.add parm1
                          sb.add $CR
                        END MACRO
                        
                        FUNCTION PBMAIN () AS LONG 'powertime2.bas
                          LOCAL date1,date2 AS IPOWERTIME
                          LOCAL sign,years,months,days AS LONG
                          LOCAL lSign, lDays AS LONG
                        
                          LOCAL sb AS ISTRINGBUILDERA
                          sb=CLASS "StringBuilderA"
                        
                          date1=CLASS "PowerTime"
                          date2=CLASS "PowerTime"
                        
                          [B]date1.now[/B]                       'assign current date and time
                          sbCR("date1.now")               'title for date1
                          sbFillAll(date1,sb)             'show all members for display
                        
                          [B]date2.now [/B]                      'assign current date and time
                          sbCR("date2.now")              'title for date2
                        
                          [B]date2.AddDays(7)[/B]                 'add days
                          'date2.AddYears(1)               'add years
                          'date2.AddMonths(1)              'add months
                          'date2.NewDate(2017,12,31)      'end of 2017 could just use another date
                          sbFillAll(date2,sb)           'show date2 members
                          date2.DateDiff(date1,sign,years,months,days)
                          sbCR("")
                        
                          sbCR("Differences:")
                          sb.add("Years") :sbCR (STR$(years))
                          sb.add("Months"):sbCR (STR$(months))
                          sb.add("Days")  :sbCR (STR$(days))
                          sb.add("Sign")  :sbCR (STR$(sign))
                          sbCR("")
                          'Mike Doty method
                          sbCR(USING$("Total days using division #,",(date2.FileTime - date1.FileTime)\%Hundred_Nanoseconds_Per_Day))
                          'Dave Biggs method
                          date2.TimeDiff (date1, lsign, lDays):ldays=ldays*lsign
                          sbCR(USING$("Total days using TimeDiff #,", ldays))
                        
                          ? sb.string,,"Add a week"
                        END FUNCTION
                        '
                        SUB sbFillAll(obj AS IPOWERTIME, sb AS ISTRINGBUILDERA)
                          sbCR(obj.timestringFull)       'hh:mm:ss:mmm (military time)
                          sbCR(obj.timestring24)         'hh:mm (military time)
                          sbCR(obj.timestring)           'hh:mm AM or PM
                          sbCR(FORMAT$(obj.month))       'month 1-12
                          sbCR(FORMAT$(obj.day))         'day 1-31
                          sbCR(FORMAT$(obj.year))        'yyyy
                          sbCR(FORMAT$(obj.dayofweek))   'day number 0-6
                          sbCR(obj.dayofweekstring)      'day name sunday-saturday
                          sbCR(obj.datestringlong)       'show date1
                          sbCR(IIF$(obj.isleapyear,"Leap year","Not leap year"))
                          sbCR("-----------------------")
                        END SUB
                        Attached Files

                        Comment


                        • #13
                          PB Powertime would be better and simpler, with less code lines?
                          I have use powertime to do difference between dates but never to verify a date entry. To check if a date entry is valid.

                          Some of the code that I see here is not simple for me. In the future I may do a sample date checker using Powertime, May need help with that.


                          Robert

                          Comment


                          • #14
                            PowerTime usually does not mean less code, but is more powerful if you need to calculate time or date differences, etc. Still need to verify input, so usually means similar year, month, day check.

                            Comment


                            • #15
                              One thing that I do not show in this post in checking date is how I check month and year . Here is what I use. Thanks everyone for you help and comments.

                              Code:
                              K=MID$(DATE1,1,2)                              'check month
                              C=SWITCH(K="01", 1 ,_
                              K="02", 1 ,_
                              K="03", 1 ,_
                              K="04", 1 ,_
                              K="05", 1 ,_
                              K="06", 1 ,_
                              K="07", 1 ,_
                              K="08", 1 ,_
                              K="09", 1 ,_
                              K="10", 1 ,_
                              K="11", 1 ,_
                              K="12", 1)
                              
                              IF C=1 THEN GOTO CONT2 ELSE ? "MONTH MUST BE 01 THRU 12": CONTROL SET FOCUS hDlg2, %TXBX3: GOTO EXITT
                              
                              '*************************
                              IF NN3<1900 OR NN3>9999 THEN ? "Year 1900-9999": CONTROL SET FOCUS hDlg2,%TXBX9: GOTO EXITT ELSE GOTO CONT3                     'check year
                              CONT3:
                              Robert

                              Comment


                              • #16
                                PowerTime showing all members of Date1 and Date2 that could be used (without StringBuilder)
                                Code:
                                #DIM ALL
                                FUNCTION PBMAIN () AS LONG
                                
                                  DIM sArray(1 TO 10) AS STRING
                                  LOCAL sign,days AS LONG
                                  LOCAL date1 AS IPOWERTIME
                                  LOCAL date2 AS IPOWERTIME
                                
                                  date1=CLASS "PowerTime"
                                  date2=CLASS "PowerTime"
                                
                                  date1.now         'set date1 to now
                                  date2.now         'set date2 to now
                                  date2.AddDays(1)  'tomorrow
                                
                                  ? CHR$("Date1 Members",$CR,Members(date1,sArray()),$CR,STRING$(40,"----"),$CR,_
                                         "Date2 Members",$CR,Members(date2,sArray())),,"Date1 & Date2 Members"
                                
                                
                                  date2.NewDate(date1.year,12,31)    'set date2 to end of year
                                  date2.TimeDiff (date1, sign, days) 'days left in year
                                  ? "Days left in year" + STR$(days)
                                
                                END FUNCTION
                                
                                FUNCTION Members(obj AS IPOWERTIME,sArray() AS STRING) AS STRING
                                  sArray(1) = obj.timestringFull           'hh:mm:ss:mmm (military time)
                                  sArray(2) = obj.timestring24             'hh:mm (military time)
                                  sArray(3) = obj.timestring               'hh:mm AM or PM
                                  sArray(4) = FORMAT$(obj.month)           'month 1-12
                                  sArray(5) = FORMAT$(obj.day)             'day 1-31
                                  sArray(6) = FORMAT$(obj.year)            'yyyy
                                  sArray(7) = FORMAT$(obj.dayofweek)       'day number 0-6
                                  sArray(8) = obj.dayofweekstring          'day name sunday-saturday
                                  sArray(9) = obj.datestringlong           'show date string
                                  sArray(10) = FORMAT$(obj.isleapyear)     'leap year 0 or 1
                                  FUNCTION = JOIN$(sArray(),$CR)
                                END FUNCTION

                                Comment


                                • #17
                                  Originally posted by Knuth Konrad View Post
                                  I wonder why you still bother with your own proprietary date code, if PB provides the PowerTime object? It even has a IsLeapYear method ...
                                  There's a difference between date/time manipulation and data entry validation.
                                  How would you use a Powertime to tell the user that the string "13012021" is a data entry error?
                                  You still need the text parsing and bounds checking before using the Powertime to manipulate entered date..


                                  Comment


                                  • #18
                                    Originally posted by Mike Doty View Post
                                    date1.now 'assign current date and time
                                    ...
                                    date2.now 'assign current date and time
                                    My previous comment applies to this post as well


                                    Comment


                                    • #19
                                      Originally posted by Robert Alvarez View Post
                                      One thing that I do not show in this post in checking date is how I check month and year . Here is what I use. Thanks everyone for you help and comments.

                                      Code:
                                      K=MID$(DATE1,1,2) 'check month
                                      C=SWITCH(K="01", 1 ,_
                                      K="02", 1 ,_
                                      K="03", 1 ,_
                                      K="04", 1 ,_
                                      K="05", 1 ,_
                                      K="06", 1 ,_
                                      K="07", 1 ,_
                                      K="08", 1 ,_
                                      K="09", 1 ,_
                                      K="10", 1 ,_
                                      K="11", 1 ,_
                                      K="12", 1)
                                      
                                      IF C=1 THEN GOTO CONT2 ELSE ? "MONTH MUST BE 01 THRU 12": CONTROL SET FOCUS hDlg2, %TXBX3: GOTO EXITT
                                      
                                      '*************************
                                      IF NN3<1900 OR NN3>9999 THEN ? "Year 1900-9999": CONTROL SET FOCUS hDlg2,%TXBX9: GOTO EXITT ELSE GOTO CONT3 'check year
                                      CONT3:
                                      Post #8 already shows a much easier month check. Just add one line to check year.

                                      'initial reasonableness checks
                                      IF lngDay < 1 THEN ? "Invalid Day"& STR$(lngDay) : EXIT FUNCTION
                                      IF lngMth < 1 OR lngMth > 12 THEN ? "Invalid Month" & STR$(lngMth) : EXIT FUNCTION
                                      If lngYear <1900 or lngYear > 9999 THEN ? "Invalid Year" & STR$(lngYear) : EXIT FUNCTION

                                      Comment


                                      • #20
                                        Best way to confirm dates is by making sure they are correct from start. A good way to do that could be to use the SysDateTimePick32 control - then no confirmation needed (also does automatic leap year check). So, welcome to Windows' world - here's a way:
                                        Click image for larger version  Name:	DatePickDlg.jpg Views:	0 Size:	5.7 KB ID:	803994
                                        '
                                        Code:
                                        '====================================================================
                                        #COMPILE EXE
                                        #DIM ALL
                                        #INCLUDE "WIN32API.INC"
                                        #INCLUDE "PBForms.INC"
                                        %IDC_DATE = 241
                                        
                                        '====================================================================
                                        FUNCTION PBMAIN () AS LONG
                                          LOCAL hDlg AS DWORD
                                        
                                          DIALOG NEW 0, "Select date",,, 116, 42, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
                                        
                                          PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR %ICC_INTERNET_CLASSES)
                                        
                                          CONTROL ADD "SysDateTimePick32", hDlg, %IDC_DATE, "", 5, 5, 60, 12, _
                                                      %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %DTS_SHORTDATEFORMAT
                                        
                                          '------------------------------------------------------------------
                                          CONTROL ADD BUTTON, hDlg, %IDOK,     "&Date",  5, 22, 50, 14
                                          CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Quit", 60, 22, 50, 14
                                        
                                          '------------------------------------------------------------------
                                          DIALOG SHOW MODAL hDlg CALL DlgProc
                                        
                                        END FUNCTION
                                        
                                        '====================================================================
                                        CALLBACK FUNCTION DlgProc() AS LONG
                                        
                                          LOCAL st AS SYSTEMTIME
                                        
                                          SELECT CASE AS LONG CB.MSG
                                          CASE %WM_INITDIALOG
                                        '      st.wYear  = 2000  ' if to set an initial date, else current date is set.
                                        '      st.wMonth = 1
                                        '      st.wDay   = 1
                                        '      DateTime_SetSystemTime(GetDlgItem(CB.HNDL, %IDC_DATE), %GDT_VALID, st)
                                        
                                          CASE %WM_COMMAND
                                              SELECT CASE AS LONG CB.CTL
                                              CASE %IDOK
                                                 IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                                     DateTime_GetSystemTime GetDlgItem(CB.HNDL, %IDC_DATE), st
                                                     MSGBOX "Year  =" + STR$(st.wYear) + $CRLF + _
                                                            "Month =" + STR$(st.wMonth) + $CRLF + _
                                                            "Day  ="  + STR$(st.wDay)
                                                    ' do whatever..
                                                 END IF
                                        
                                              CASE %IDCANCEL
                                                 IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN 'end prog
                                                    DIALOG END CB.HNDL
                                                 END IF
                                              END SELECT
                                        
                                          END SELECT
                                        END FUNCTION
                                        '

                                        Comment

                                        Working...
                                        X