WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Boxes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Calender Pick Dialog

 Keywords:  Calender Control Date Picker

This code will present the user with a calender. The user can then pick a date. Ability to move through months and years is also included.

#DefineFunction CalenderControl(now)

while @true
   startingdate=strcat(strsub(now,1,8), "01:00:00:00")
   firstday=((TimeJulianDay(startingdate)+5) mod 7)+1
   ;startingday=ItemExtract(((TimeJulianDay(startingdate)+5) mod 7)+1, "Sun Mon Tue Wed Thu Fri Sat", " ")
   daysincurrentmonth=itemextract(3, timesubtract(timeadd(startingdate, "0000:01:00:00:00:00") , "0000:00:01:00:00:00"), ":")

            yyyear=ItemExtract(1,now,":")
            yymonth=ItemExtract(2,now,":")
            yymonth=ItemExtract(yymonth,"January February March April May June July August September October November December"," ")
            dropwild("mydialog*")
            
            intcontrol(52,0,1,0,0)
            MyDialogFormat=`WWWDLGED,5.0`
            MyDialogCaption=strcat(`Calendar for `,yymonth,` `,yyyear)
            MyDialogX=4000   ; center horizontally
            MyDialogY=4000   ; center vertically
            MyDialogWidth=150
            MyDialog01=`8,3,18,DEFAULT,STATICTEXT,DEFAULT,"Sun"`
            MyDialog02=`28,3,18,DEFAULT,STATICTEXT,DEFAULT,"Mon"`
            MyDialog03=`48,3,18,DEFAULT,STATICTEXT,DEFAULT,"Tue"`
            MyDialog04=`68,3,18,DEFAULT,STATICTEXT,DEFAULT,"Wed"`
            MyDialog05=`88,3,18,DEFAULT,STATICTEXT,DEFAULT,"Thu"`
            MyDialog06=`108,3,18,DEFAULT,STATICTEXT,DEFAULT,"Fri"`
            MyDialog07=`128,3,18,DEFAULT,STATICTEXT,DEFAULT,"Sat"`
            
            bnum = 8
            col = (firstday * 20) - 16     ; decide at wich column to start the display
            row = 14
            for n = 1 to daysincurrentmonth
               if bnum < 10 then bnum = strcat("0", bnum)
               MyDialog%bnum% = `%col%,%row%,18,DEFAULT,PUSHBUTTON,DEFAULT,"%n%",%n%`
               bnum= bnum + 1
               col = col + 20
               if col == 144
                  col = 4
                  row = row + 18
               endif
            next
            
            ;if col!=4 then row=row+18
            row=118
            
            MyDialog%bnum% = `4,%row%,33,DEFAULT,PUSHBUTTON,DEFAULT,"<< year",51`
            bnum= bnum + 1
            MyDialog%bnum% = `39,%row%,33,DEFAULT,PUSHBUTTON,DEFAULT,"< month",50`
            bnum= bnum + 1
            MyDialog%bnum% = `75,%row%,33,DEFAULT,PUSHBUTTON,DEFAULT,"month >",60`
            bnum= bnum + 1
            MyDialog%bnum% = `110,%row%,33,DEFAULT,PUSHBUTTON,DEFAULT,"year >>",61`
            bnum= bnum + 1
            row=row+14
            MyDialog%bnum% = `4,%row%,139,DEFAULT,PUSHBUTTON,DEFAULT,"Cancel",0`
            
            MyDialogNumControls= bnum
            MyDialogHeight=row+18
            
            ButtonPushed=Dialog("MyDialog")


   switch @true
        case buttonpushed == 61       ; next year
        now = timeadd(startingdate, "0001:00:00:00:00:00")
        break

        case buttonpushed == 60       ; next month
        now = timeadd(startingdate, "0000:01:00:00:00:00")
        break

        case buttonpushed == 51      ;previous year
        now = timesubtract(startingdate, "0001:00:00:00:00:00")
        break

        case buttonpushed == 50       ;previous month
        now = timesubtract(startingdate, "0000:01:00:00:00:00")
        break

        case @true                     ; date selected
        if buttonpushed < 10 then buttonpushed = strcat("0", buttonpushed)
        return ( itemreplace(buttonpushed, 3, startingdate, ":"))
        break
   endswitch
endwhile

;UDF should never get here
return("***ERROR***")

#EndFunction

sdate=TimeYmdHms()
newdate=CalenderControl(sdate)
Message("Date Selected",newdate)



Article ID:   W14986
File Created: 2001:11:08:12:41:18
Last Updated: 2001:11:08:12:41:18